【发布时间】:2020-10-23 15:22:28
【问题描述】:
我想在 JFreeChart 上创建多个 ScatterPlot 图表,为此我使用了函数 createCombinedChart()。使用我当前的代码,我得到了多个图表,就像您可以找到的 CombinedXYPlotDemo1 一样,但这些是折线图,我希望它们作为 ScatterPlot。
我找到了这个question,但尝试后我不知道如何让它工作(也许我只是不明白如何使用它)
这是我的代码示例(它与演示代码非常相似 + 我从数据库中检索并添加了时间轴)。
public class DatabaseChart extends ApplicationFrame {
private static final long serialVersionUID = 1L;
public DatabaseChart(final String title) {
super(title);
final JFreeChart chart = createCombinedChart();
final ChartPanel panel = new ChartPanel(chart, true, true, true, true, true);
panel.setPreferredSize(new java.awt.Dimension(1000, 500));
setContentPane(panel);
}
/**
* Creates a combined chart.
*
* @return the combined chart.
*/
private JFreeChart createCombinedChart() {
// create subplot 1
final XYDataset data1 = createDataset1();
final XYItemRenderer renderer1 = new StandardXYItemRenderer();
final NumberAxis rangeAxis1 = new NumberAxis("Axis");
rangeAxis1.setLabelPaint(Color.RED);
final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
// create subplot 2
[...]
// create subplot 3
[...]
// parent plot...
final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
//plot.setRenderer(new XYLineAndShapeRenderer(false,true)); ??
plot.setGap(25.0);
// add the subplots...
ValueAxis domainAxis = new DateAxis("");
plot.setDomainAxis(domainAxis);
plot.add(subplot1, 1);
plot.add(subplot2, 1);
plot.add(subplot3, 1);
plot.setOrientation(PlotOrientation.VERTICAL);
// return a new chart containing the overlaid plot...
return new JFreeChart("Name",JFreeChart.DEFAULT_TITLE_FONT, plot, false);
}
/**
* Creates a sample dataset.
*
* @return Dataset1.
*/
private JDBCXYDataset createDataset1() {
[...]
}
//Same for Dataset2 and Dataset3
public static void main(final String[] args) {
[...]
}}
那么有没有一种简单的方法可以将我得到的折线图转换为 ScatterPlot 图表?
【问题讨论】:
标签: java jfreechart