How to put benchmark line on barchart?

后端 未结 2 1453
野趣味
野趣味 2021-01-24 05:06

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

How can this be achieved using jasper reports?

2条回答
  •  再見小時候
    2021-01-24 05:43

    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

    
        
       ....
        
       ...
    
    

提交回复
热议问题