Line Chart - Customize point and line color

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.

Line Chart - Customize point and line color

Post by Louis » Fri Dec 10, 2021 8:30 pm

I have a line chart that I need to have the values on the points, and a specific point needs to be a different shape and color. I have everything working except that the line color is changing with the point color (line between previous point and current point). I'm using he "getItemPaint" method to change the point color, I couldn't identify another method to do this. Is there a way to change the color of just the point shape and not the line?

The following is my customizer class.

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());
    }

}
Thanks, Louis

Locked