I am trying to show a histogram of an image and show only some colors. I already did this with JFreeChart and createXYLineChart and got all the data by iterating all the pixels.
To speed this up, I am trying to do this using "createHistogram". I followed this code .
To update the chart with new values, I used these two methods:
XYPlot plot = (XYPlot) chart.getPlot(); plot.setDataset(setHistogram(red, green, blue));
Configure the Histogram of the method that HistogramDataset returns, depending on which checkbox is activated (Boolean red, green, and blue).
This works correctly as intended.
The second thing I have to do when I do this is updating the colors of each series, because otherwise they get the default value. I did this more or less with the same procedure as with the values:
private void setHistogramColors(boolean red, boolean green, boolean blue) { XYPlot plot = (XYPlot) chart.getPlot(); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setBarPainter(new StandardXYBarPainter()); Paint[] paintArray = null; if (red) { if (green) { if (blue) { paintArray = new Paint[3]; paintArray[0] = new Color(0x80ff0000, true);// translucent red, green & blue paintArray[1] = new Color(0x8000ff00, true); paintArray[2] = new Color(0x800000ff, true); } else { paintArray = new Paint[2]; paintArray[0] = new Color(0x80ff0000, true); paintArray[1] = new Color(0x8000ff00, true); } } else { paintArray = new Paint[1]; paintArray[0] = new Color(0x80ff0000, true); } } else if (green) { if (blue) { paintArray = new Paint[2]; paintArray[0] = new Color(0x8000ff00, true); paintArray[1] = new Color(0x800000ff, true); } else { paintArray = new Paint[1]; paintArray[0] = new Color(0x8000ff00, true); } } else if (blue){ paintArray = new Paint[1]; paintArray[0] = new Color(0x800000ff, true); } else { return; } plot.setDrawingSupplier(new DefaultDrawingSupplier( paintArray, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); }
But for what I see, this only works when I draw the code for the first time, and the following stories from different episodes will take on the sames colors. Here is an example: RGB is the color that they should be: [
When I update red, you get to the green histogram and green to blue: 
Is there any way to fix this?