折线图自定义问题 - JFreeChart

LineChart custmization issue - JFreeChart

我正在尝试使用 JFreeChart 创建图表。 我需要它有蓝线、白色背景的方形标记并显示每个标记上方的值。但我需要它非常非常简单。代码 belhow 在一个方法中,该方法从数据库中恢复数据并将其放入 dataset,并将图表生成为 JPEG 图像。

图表已生成,但我找不到按需要自定义图表的方法。

我的代码如图:

// * 'graphicValues' data set is already created *

    JFreeChart graphicObject = ChartFactory.createLineChart("Classes",
            "months", //linha X
            "", //linha Y
            graphicValues, 
            PlotOrientation.VERTICAL, 
            true, 
            true,
            false);

    //Only command that seems to work
    graphicObject.setBackgroundPaint(Color.WHITE); 

     // * from here on, code works fine, I just save it as a file somewhere *

任何人都可以帮我将线条设置为蓝色并将值显示为方形标记上的标签吗?

非常感谢!

作为 ChartFactory says, ChartFactory.createLineChart

的文档

Creates a line chart with default settings. The chart object returned by this method uses a CategoryPlot instance as the plot, with a CategoryAxis for the domain axis, a NumberAxis as the range axis, and a LineAndShapeRenderer as the renderer

因此,您使用该方法得到的都是默认设置,无法自定义图表。

要自定义图表,您可能不得不放弃 ChartFactory,并动手对某些 JFreeChart 类.[=19= 进行子类化]

我建议您首先查看 ChartFactorysource 代码——您将了解它如何创建图表、"renderer" 和 "plot" 用于渲染图表。您可能必须对其中的一个或多个进行子类化,尤其是渲染器。查看 LineAndShapeRenderer 源代码以了解渲染器的工作原理。