Change label color in JFreeChart

Anyone who has experience using JFreeChart has a way to change the color of my labels for my XY axes. Now I am using XYPlot , and I want to change the color of the labels on my axes. Is there any way to do this?

+7
java jfreechart
source share
2 answers

You can use setTickLabelPaint() for your desired Axis .

+8
source share

I used this code to change the color of all my shortcuts:

 private void setFontColor(Color fontColor) { JFreeChart chart = getChart(); chart.getTitle().setPaint(fontColor); Plot plot = chart.getPlot(); if (plot instanceof CategoryPlot) { setAxisFontColor(((CategoryPlot) plot).getDomainAxis(), fontColor); setAxisFontColor(((CategoryPlot) plot).getRangeAxis(), fontColor); } else if (plot instanceof XYPlot) { setAxisFontColor(((XYPlot) plot).getDomainAxis(), fontColor); setAxisFontColor(((XYPlot) plot).getRangeAxis(), fontColor); } } private void setAxisFontColor(Axis axis, Color fontColor) { if (!fontColor.equals(axis.getLabelPaint())) axis.setLabelPaint(fontColor); if (!fontColor.equals(axis.getTickLabelPaint())) axis.setTickLabelPaint(fontColor); } 

If you use subtitles, you also need to add them.

0
source share

All Articles