How to draw a horizontal line in a vertical bars chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Jorge Santos

How to draw a horizontal line in a vertical bars chart

Post by Jorge Santos » Tue Jan 07, 2003 6:30 pm

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));

...

David Gilbert

Re: How to draw a horizontal line in a vertical bars chart

Post by David Gilbert » Tue Jan 07, 2003 11:37 pm

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

Locked