1

I am using JFreeChart to plot a line graph. The app reads in sensory data every 100 milliseconds so for a few minutes of capture it's a a lot of data. I don't plot the graph dynamically, it is static. I am using a Category plot since the axis can sometimes be decimal values, other times it can be strings, other times it can be boolean. My issue is the X axis (time) has so much data I can't make out the text:

enter image description here

Anyone know what I can do here to? Any tips or tricks to deal with this will be great!

 private CategoryDataset createDataset() {
    String series1 = "First";
    String series2 = "Second";
    String category1 = "Category 1";
    String category2 = "Category 2";
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < time.size(); i++) {
        dataset.addValue(Math.random(), series1, time.get(i));
    }
    return dataset;

}

private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createLineChart(
            "Line Chart Demo 6", // chart title
            "Time", // x axis label
            "RPM", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL,
            true, // include legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final CategoryItemRenderer renderer = (CategoryItemRenderer) plot.getRenderer();

    plot.setRenderer(renderer);



    return chart;

}

public void setLists(ArrayList<String> time) {
    this.time = time;
    final CategoryDataset dataset = createDataset();
    final JFreeChart chart = createChart(dataset);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
}
Mark Manickaraj
  • 1,661
  • 5
  • 28
  • 44

1 Answers1

0

You can turn off the Lables and TickMarks by adding:

CategoryPlot plot = (CategoryPlot) chart.getPlot();
CategoryAxis cx = new CategoryAxis();
cx.setTickLabelsVisible(false);
cx.setTickMarksVisible(false);
plot.setDomainAxis(cx);

If you wantto display a subset of the labels (every nth value) then you will need to subclass CategoryAxis so you can overide CategoryAxis#drawCategoryLabels() andCategoryAxis#drawTickMarks()

GrahamA
  • 5,875
  • 29
  • 39
  • The issue is that I need to show each and every single one of those ticks. Is there a way to make the graph horizontally scrollable? – Mark Manickaraj Dec 03 '13 at 19:15
  • Using a scroll pane in covered in the [samples](http://www.jfree.org/jfreechart/samples.html) – GrahamA Dec 04 '13 at 09:08