4

I just want to get the data points on my chart to show up, how do I do this? The plot shows up fine as a line plot but I want small markers for each individual data point.

JFreeChart portion of the app is:

    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;
}  
fred basset
  • 9,774
  • 28
  • 88
  • 138

1 Answers1

7

JFreeChart.createTimeSeriesChart() uses an XYLineAndShapeRenderer, so start by making the shapes visible.

renderer.setSeriesShapesVisible(true);

This related example illustrates a few of the other methods that affect the appearance.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 2
    This method now requires 2 params. An `int` and a `boolean`. The `int` represents the serie, and the `boolean` is the flag. So the syntax now looks like `renderer.setSeriesShapesVisible(0, true);`. – Moduo Dec 29 '13 at 10:55