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 8381529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:43:09+00:00 2026-06-09T16:43:09+00:00

I am working on a program that takes an array of doubles and displays

  • 0

I am working on a program that takes an array of doubles and displays them all in one line on a horizontal bar graph. Right now it works except for the coloring. I have an indeterminate amount of rows so the data is added to the graph like this:

public CategoryDataset createDataset() {
    DefaultCategoryDataset bardataset1 = new DefaultCategoryDataset();
    for (int i = 0; i < nanoArray.length; i++) {
        bardataset1.addValue(nanoArray[i], "Packet" + i, "Class A");
        bardataset1.addValue(startgap, "Packet Gap" + i, "Class A");
    }
}

This stacks the data properly but because there are around 300 different rowKeys it assigns 300 different colors. I attached this picture to show you what it looks like:

http://i.imgur.com/hg33P.png

As you can see this makes the data completely unreadable. What I want is to see bars of alternating colors of red then blue.

Edit: I have found the answer; I used jcern’s method. I also wrote a for loop that iterates through the length of my double array and assigns a color based on whether it is even or odd.

for (int i = 0; i < packetCount; i++) {
        setSeriesToolTipGenerator(i, new StandardCategoryToolTipGenerator());
        if (i % 2 == 0) {
            setSeriesPaint(i, new Color(255, 0, 0));
        } else {
            setSeriesPaint(i, new Color(0, 0, 0));
        }
    }
  • 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-06-09T16:43:10+00:00Added an answer on June 9, 2026 at 4:43 pm

    You need to create a new renderer and specify that to the plot.

    First, you’ll create a render that has the two colors you want:

    CategoryItemRenderer renderer = new StackedBarRenderer {
         private Paint[] colors = new Paint[] {
            new Color(255, 0, 0), 
            new Color(0, 0, 255)
         }
    
         public Paint getSeriesPaint(int series) {
           return colors[(series % 2)];
         }
    };
    

    Then, grab the plot and specify which render you want to use:

    if(chart.getPlot() instanceof CategoryPlot){
      chart.getCategoryPlot().setRenderer(renderer);
    }
    

    Hopefully, that should get you where you want to be.

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

Sidebar

Related Questions

The program that I am working on takes a file and parses it line
I'm working on a program that takes in a Wavefront .obj file and eventually
I'm working on a program for class that takes in a number from 0
I am writing a program that takes letters and converts them to telephone numbers.
I am working with a simple command line application that takes in ASCI text
I'm trying to make a program that takes in one argument, a file, and
I'm working on a program that uses HTML/CSS/Javascript/JQuery for its user interface. One of
Ok so I'm working on a program that takes in an image, isolates a
Currently I'm working on a program that parses through a file and takes characters
I'm working on a program that will sort files based on extension I currently

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.