focus1691
focus1691

Reputation: 351

JFreeChart solution to draw a graph with a lot of data (>100) or (>1000)

I have a graph with a lot of data (>100) or (>1000). Here's how JFreeChart prints the graph now.

image

There are only 11 data points, and each person's name should appear on the x axis, but there are ellipses in place. Is there an ideal way to print large numbers of data like this?

public void barchartResults(ArrayList<Person> results, String testName) {
    int i;
    setLayout(new FlowLayout(FlowLayout.LEFT, 20, 20));
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    String test = results.get(0).getTrait();

    for (i = 0; i < results.size(); i ++) { // Iterate until the end of the results array
        dataset.setValue(results.get(i).getScore(), results.get(i).getTrait(), results.get(i).getName());
    }

    JFreeChart chart = ChartFactory.createBarChart3D( testName + ": " + test,
            "Examinees", "Score", dataset, PlotOrientation.VERTICAL, true, true, false );

    ChartPanel chartPanel = new ChartPanel(chart, W, H, W, H, W, H, false, true, true, true, true, true); 
    chart.setBorderVisible(true);
    chartPanel.setSpaceBetweenGroupsOfBars(1);
    this.add(chartPanel);
    revalidate();
    repaint();
}

Upvotes: 1

Views: 291

Answers (1)

trashgod
trashgod

Reputation: 205785

Some options:

  • Invoke setVerticalTickLabels() on your domain axis, as shown here.

  • Invoke setCategoryLabelPositions() with the desired angle, as shown here and here.

  • Use a SlidingCategoryDataset,as shown here and in the demo.

Upvotes: 1

Related Questions