4

我只想让图表上的数据点显示出来,我该怎么做?该图显示为线图,但我想要每个单独的数据点的小标记。

该应用程序的 JFreeChart 部分是:

    private XYDataset createDataset() {
    final TimeSeries inclinometerAngles = new TimeSeries(TimeUnit.SECONDS);

    // Add all data from the map to the dataset
    final Set<Date> keys = data.keySet();
    for (Date date : keys) {
        Record r = data.get(date);
        if (r.mcInclinometerAngle != null) {
            inclinometerAngles.add(new Second(date), r.mcInclinometerAngle);
        }
    }        

    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(inclinometerAngles);
    return dataset;
}   

private void setupGraphics() {
    final XYDataset dataset = createDataset();
    final JFreeChart chart = createChart(dataset);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setMouseZoomable(true, false);
    setContentPane(chartPanel);
}

private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Tracker Analysis", 
        "Date", 
        "Value",
        dataset, 
        true, 
        true, 
        false
    );

    final XYPlot plot = chart.getXYPlot();
    XYItemRenderer renderer = plot.getRenderer();

    final StandardXYToolTipGenerator g = new StandardXYToolTipGenerator(
        StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
        new SimpleDateFormat(), new DecimalFormat("0.00")
    );
    renderer.setToolTipGenerator(g);
    renderer.setItemLabelsVisible(true);
    return chart;
}  
4

1 回答 1

7

JFreeChart.createTimeSeriesChart()使用XYLineAndShapeRenderer,所以首先让形状可见。

renderer.setSeriesShapesVisible(true);

此相关示例说明了影响外观的其他一些方法。

于 2012-04-24T23:33:58.567 回答