2

We are using the jfreechart with Jasper reports and we are struggling to put the benchmark line on the bar chart.

We need to add the redline on bar

How can this be achieved using jasper reports?

Alex K
  • 22,315
  • 19
  • 108
  • 236
Santosh
  • 202
  • 3
  • 16
  • Hi Santosh, can you post code sample of what you have tried so far? that will make it easier for others to correct/answer. – dubes Feb 26 '16 at 10:30

3 Answers3

3

To customize your bar chart in jasper report create a customizer class (ChartCustomizer) extending the JRChartCustomizer.

public void customize(JFreeChart chart, ChartComponent chartComponent)
{
  //get the ploy
  CategoryPlot plot = (CategoryPlot) chart.getPlot();

  //Now add your markers
  ValueMarker vm = new ValueMarker(200); //200 is the position you like it to be
  vm.setPaint(Color.RED);
  vm.setStroke(new BasicStroke(1));
  vm.setLabel("BeanchMark value"); //The label
  vm.setLabelAnchor(RectangleAnchor.TOP);
  vm.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
  plot.addRangeMarker(vm);
}

add the class to classpath and in jrxml set the customizerClass attribute

<barChart>
    <chart customizerClass="my.package.ChartCustomizer">
   ....
    </chart>
   ...
</barChart>
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
0

We have resolved it by using the following code in customise class

ValueMarker marker = new ValueMarker(30);
    marker.setLabel("Average 30%");
    marker.setPaint(Color.black);
    plot.addRangeMarker(marker);

However we need to change the label position, currently it is showing at the start of the line.

Santosh
  • 202
  • 3
  • 16
0

For one single horizontal line you can use provided chart customizer:

Go to Chart -> Properties -> Chart (tab) -> Chart customizers

Chart properties

There you can add a Range Interval Marker and configure it with start and end values with the desired value (35 in your example).

This way an horizontal line will be drawn in the 35 vertical value as you wanted.

Paco Abato
  • 3,920
  • 4
  • 31
  • 54