I realize that this question has been asked before, but other solutions have not worked out for me and I'm hoping others could find where the inconsistencies may lie.
I'm using JFreeChart in iText and building a bar chart using this method below:
DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
String rowKey = "score";
for(int i = 0; i <= 100; i++)
{
double frequency = Collections.frequency(scoreList,i);
dataSet.setValue(frequency, rowKey, i+"");
}
JFreeChart chart = ChartFactory.createBarChart("", "Score Distribution (%)", "Count", dataSet, PlotOrientation.VERTICAL, false, true, false);
It's a pretty simple way to make a chart (although I don't know what the false, true, false
means within the createBarChart()
method). The problem is that there are 101 values on the x-axis and they don't all fit onto the screen/page.
I've tried drawing only every 2/3/n-th value, but that causes the graph to become something different entirely, so I only want the labels to appear less, not the actual values and graph bars themselves.
Every other solution presented on stackoverflow has suggested using XYPlot
. But when I try to use XYPlot
, I get: java.lang.ClassCastException: org.jfree.chart.plot.CategoryPlot cannot be cast to org.jfree.chart.plot.XYPlot
. Although the language here appears straightforward, I don't know why this error appears. Is it because it's strictly a bar graph that's causing this error?
I've been able to do this:
CategoryPlot plotCat = (CategoryPlot) chart.getPlot();
ValueAxis yAxis = plotCat.getRangeAxis();
CategoryAxis xAxis = (CategoryAxis) plotCat.getDomainAxis();
So it seems like the x- and y-axes require different types of axis names? I'm confused about this too.
In short: how do I skip printing every n-th label on my x-axis for a bar chart?