Points and Lines - Different Colors

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Louis
Posts: 2
Joined: Fri Dec 10, 2021 7:41 pm
antibot: No, of course not.

Points and Lines - Different Colors

Post by Louis » Tue Dec 14, 2021 7:15 pm

I have a line chart that I'm using a customizer to set the point shape as well as the point color. The shapes and the shape colors are working great. My issue is that when I change the color of a single point, the line segment between the previous point and the point that has the different color also changes. I need the entire line to be a single color. An example of the chart and the custom code are below. It's kind of hard to tell in the image but the line between 0.57 and 0.60 is black instead of blue.

Image

Code: Select all

public class LineChartItemLabelCustomizer implements JRChartCustomizer {
	static Color jtsBlue = new Color(0, 125, 193);

    static class CustomRenderer extends LineAndShapeRenderer {
		private static final long serialVersionUID = -2378925128764898991L;

        public CustomRenderer() {
            this.setBaseItemLabelsVisible(Boolean.TRUE);
            this.setBaseFillPaint(jtsBlue);

            Shape shape = new Ellipse2D.Double(-3, -3, 5, 5);
            this.setSeriesShape(0, shape); 

            DecimalFormat format = new DecimalFormat("##0.00");
            this.setBaseItemLabelGenerator((CategoryItemLabelGenerator) new StandardCategoryItemLabelGenerator("{2}", format, format));
            
            Font font = new Font("JTSOpenSans", Font.PLAIN, 8);
            this.setBaseItemLabelFont(font);
        }

        @Override
        public Paint getItemPaint(int series, int category) {
            if (((String)this.getPlot().getDataset().getColumnKey(category)).contains("WAL"))
                return Color.black;
            else
                return jtsBlue;
        }
        
        @Override
        public Shape getItemShape(int series, int category) {
            if (((String)this.getPlot().getDataset().getColumnKey(category)).contains("WAL"))
                return ShapeUtilities.createDiamond(3);
            else
                return super.getItemShape(series, category);
        }
    }

    @Override
    public void customize(JFreeChart jfc, JRChart jasperChart)
    {
        CategoryPlot jfcPlot; 

        jfcPlot = (CategoryPlot) jfc.getPlot();
        
        jfcPlot.setDomainGridlinesVisible(true);
        jfcPlot.getDomainAxis().setLowerMargin(.01);
        jfcPlot.getDomainAxis().setUpperMargin(.01);

        jfcPlot.setRenderer(new CustomRenderer());
    }

}

Locked