Hi people
I need to draw a horizontal line in a vertical bar chart (a threshold value)
I know how to do that in a XY chart (it is explained in other topics in this forum) but not in a bar chart.
When I try to take my plot as a XYPlot object (with getXYPlot method from JFreeChart class) I have a ClassCastException.
Thank you very much.
The code in question...
...
// Build a bars chart with three series and 5x5 categories
Number[][] oTmpValues = new Number[3][POSITIONS_X*POSITIONS_Y];
oTmpValues[0] = aTotDensity;
oTmpValues[1] = aMaxDensity;
oTmpValues[2] = aMinDensity;
// Create the object with the values
DefaultCategoryDataset oDataSet = new DefaultCategoryDataset(oTmpValues);
// Set categories and series names
oDataSet.setCategories( CATEGORIES );
oDataSet.setSeriesNames( SERIES_NAMES);
// Create the chart with legend
JFreeChart oChart = ChartFactory.createVerticalBarChart(CHART_TITLE, CATEGORIES_NAME,
VALUES_NAME, oDataSet, true);
XYPlot oPlot = oChart.getXYPlot();
// Draw the threshold star number as an horizontal line
oPlot.addRangeMarker(new Marker(6000.0));
...
How to draw a horizontal line in a vertical bars chart
Re: How to draw a horizontal line in a vertical bars chart
Hi Jorge,
The bar charts are based on the CategoryPlot class, not the XYPlot class...but apart from that the approach is pretty similar:
CategoryPlot plot = myChart.getCategoryPlot();
plot.addRangeMarker(...);
Regards,
Dave Gilbert
The bar charts are based on the CategoryPlot class, not the XYPlot class...but apart from that the approach is pretty similar:
CategoryPlot plot = myChart.getCategoryPlot();
plot.addRangeMarker(...);
Regards,
Dave Gilbert