Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7037615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:34:00+00:00 2026-05-28T01:34:00+00:00

I have an ArrayList<Double> , the values of which are converted into slices of

  • 0

I have an ArrayList<Double>, the values of which are converted into slices of an Arc2D.Pie graph based on size (i.e., an array of {1d,1d,2d,4d} would create a graph with four slices, two of which occupy an eighth of the graph each, one of which occupies a fourth, and one of which occupies a half; together, the slices would be arranged to form a full circle). Each of these slices is colored differently both to allow for easy mapping of slices to other indicators (names, etc.) and to avoid blandness.

My algorithm for selecting colors was initially quite simple:

public Color getColor(int index, int total) {
    return Color.getHSBColor((float) index / (float) total, 1f, 1f);
}

However, while this works well with most colors (red and blue, to name a few), some, such as cyan (especially prominent as the second element in a set of two; e.g., an array of {1d, 3d}) are not easily viewable by the human eye, as they are too light.

I have since changed the algorithm to

return Color.getHSBColor((float) index / (float) total, 1f, 0.8f);

in an attempt to darken the colors; however, cyan is still hard to see, and lowering the brightness further makes the colors rather hard to distinguish.

Does anyone have a nice, preferably simple algorithm that will create a spectrum of colors that are all easily viewable? A good test would be to generate yellowish and cyanish colors and see if they are easily viewable on a white background.

Thanks!

WC

EDIT: I have now improved my algorithm to make more varied colors, by varying saturation and lightness. The colors look choppier, though; any more ideas?

New algorithm:

float hue = (float) seriesIndex / (float) totalSeries;
int steps = 4;
float saturation = ((seriesIndex) % steps / (2f * steps)) + (0.5f);
float brightness = ((seriesIndex + ((steps + 1) / 2f)) % (steps + 1f) / (2f * (steps + 1f))) + 0.5f;
Color c = Color.getHSBColor(hue, saturation, brightness);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:34:01+00:00Added an answer on May 28, 2026 at 1:34 am

    The best algorithm I’ve found so far uses a previous SO algorithm that’s I’ve modified. I keep MIX at a constant light gray (Color.LIGHT_GRAY), and use a seeded Random object so that the color is always the same for each iteration, but different between.

    Random random = new Random(seriesIndex);
    int red = random.nextInt(256);
    int green = random.nextInt(256);
    int blue = random.nextInt(256);
    
    // mix the color
    if (MIX != null) {
        red = (red + MIX.getRed()) / 2;
        green = (green + MIX.getGreen()) / 2;
        blue = (blue + MIX.getBlue()) / 2;
    }
    
    Color c = new Color(red, green, blue);
    

    It turns out with nice-looking colors that are fairly discernable.

    Example image

    Thanks to nmjohn for helping me solve this, giving me ideas, and pointing me in the right direction!

    WC

    NOTE: I’ll leave this open for two days. If anyone comes up with a nicer algorithm, I’ll accept his. Otherwise, I’ll accept this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array List<double[]> values = new ArrayList<double[]>(); values.add(new double[] { 12.3, 12.5,
So far I have def toDoubleArray(list: ArrayList<Double>): Array[Double] { ... } Which is not
I have the following array ArrayList<double[]> db_results = new ArrayList<double[]>(); and I would like
I have a two-dimension ArrayList that contains double values: ArrayList<ArrayList<Double>> data = new ArrayList<ArrayList<Double>>();
I have an Hashmap <integer, Arraylist<Double>> . I would like to make a copy
I have this ArrayList: ArrayList<Double> debtList = datasource.debtList; ArrayList<Double> feeList = datasource.feeList; How would
Here I have class x{ ArrayList<Double> values; x() { values= new ArrayList<Double>(); } //here
At the moment inside the class I have ArrayList which the objects are stored
I have an arraylist called fetchContactName() which returns all names (31) in my contact
i have an arraylist of strings in my servlet which im passing forwarding using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.