3

I am using Line Chart element chart wizard to display a line chart in JasperReport based on the data read from a csv file. The line chart came out fine. The problem is for me to display a vertical line marker based on certain category value. I have tried using Multi-Axis Chart and setting up the second chart as I needed. But the moment I combined it, it will either make my first line chart haywire or my second line chart goes horizontal!

So, I have tried using Chart Customizer, export to jar, add it in Build Path, add it in Chart's Customizer properties. But, it fails to display what I wanted. Below is the code:

public class Lot_VerticalLine implements JRChartCustomizer {

    public static void main(final String args) { 
       @SuppressWarnings("unused")
       final Lot_VerticalLine demo = new Lot_VerticalLine();
       //demo.customize(null, null);
    }

    public void customize(JFreeChart jfc, JRChart jrc)  {
        CategoryMarker marker = new CategoryMarker("Category Axis");
        CategoryPlot plot = jfc.getCategoryPlot();

        marker.setLabel("Band Y");
        marker.setPaint(Color.red);
        marker.setOutlinePaint(Color.red);
        marker.setDrawAsLine(true);
        marker.setAlpha(0.5f);
        marker.setLabelAnchor(RectangleAnchor.TOP);
        marker.setLabelTextAnchor(TextAnchor.TOP_CENTER);
        marker.setLabelOffsetType(LengthAdjustmentType.CONTRACT);
        plot.addDomainMarker(marker, Layer.BACKGROUND);
    }

    private void addMarker(Plot plot, Marker marker) {
            ((CategoryPlot) plot).addDomainMarker((CategoryMarker) marker);
            CategoryItemRenderer renderer = (CategoryItemRenderer) ((CategoryPlot) plot).getRenderer();
    }
}

What did I do wrong?

Alex K
  • 22,315
  • 19
  • 108
  • 236
fauzahMM
  • 31
  • 3
  • I'd expect the `CategoryMarker` key to be a specific category key, e.g. `"Category 3"` shown [here](https://stackoverflow.com/a/11391403/230513), rather than an axis label such as `"Category Axis"`. – trashgod Mar 14 '20 at 18:21

0 Answers0