How to add a vertical line to a bar chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
darrellu
Posts: 3
Joined: Wed Jan 25, 2017 8:45 pm
antibot: No, of course not.

How to add a vertical line to a bar chart

Post by darrellu » Wed Jan 25, 2017 9:56 pm

I need to add a vertical line to a bar chart as shown in the following post: http://peltiertech.com/Excel/Charts/Add ... rrBar.html

I am using Pentaho Report Designer (which uses JFreeCharts) to create the bar chart. Pentaho Report Designer has a graphical user interface for charting but also contains an extension that allows me to customize the chart. So for example, I could implement the following beanshell script to add a horizontal line to the chart. Can someone provide me with the syntax to add a vertical line to a chart as shown in the above post?

Code: Select all

import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.IntervalMarker;
import org.jfree.chart.plot.ValueMarker;
import org.jfree.ui.Layer;

CategoryPlot plot = chart.getCategoryPlot();
plot.addRangeMarker(new IntervalMarker(4900, 5000), Layer.BACKGROUND);
return chart;

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: How to add a vertical line to a bar chart

Post by paradoxoff » Fri Jan 27, 2017 1:03 pm

Code: Select all

categoryplot.addDomainMarker(new CategoryMarker(keyOfTheCategory));
This will place the marker in the center of the category.
If you need to place the marker freely along the x axis, you will have to use an XYPlot with an XYBarRenderer.

darrellu
Posts: 3
Joined: Wed Jan 25, 2017 8:45 pm
antibot: No, of course not.

Re: How to add a vertical line to a bar chart

Post by darrellu » Fri Jan 27, 2017 3:56 pm

Thanks paradoxoff - That's exactly what I was looking for and it worked perfectly!

Locked