开发者

Changing color of labels in JFreeChart

Anybody that has experience using JFreeChart, is there a way to change the color of my labels for my XY axes. Right now I'm using a XYPlot 开发者_如何学编程and I want to change the color of the labels on my axes. Is there a way to do this?


You should be able to use setTickLabelPaint() on the desired Axis.


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

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 need to add them too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜