2

I'm struggling with the dual X-axis chart with jfree chart. After a few trials with a chart customizer it still doesn't work. I would like to have events based labels on the axis that are in my datasource. The problem is the second x-axis does not show. Here is my code:

public class BurnupTimelineChartCustomizer extends JRAbstractChartCustomizer {
private static final String Y_AXIS_MAX_VALUE = "yaxisMaxValue";

private static final String EXPECTED_TOTAL_SCOPE = "expectedTotalScope";
@Override
public void customize(JFreeChart chart, JRChart jasperChart) {

    Double yaxisMaxValue = (Double) this.getParameterValue(Y_AXIS_MAX_VALUE);
    Double expectedTotalScope = (Double) this.getParameterValue(EXPECTED_TOTAL_SCOPE);
    CategoryPlot plot = chart.getCategoryPlot();

    // Value Marker
    ValueMarker marker = new ValueMarker(Math.max(yaxisMaxValue,expectedTotalScope));
    marker.setPaint(Color.black);
    plot.addRangeMarker(marker);
    // Dual Axis
    CategoryAxis sprintAxis = new CategoryAxis("TimeLine Axis");
    plot.setDomainAxis(1, sprintAxis );
    plot.mapDatasetToDomainAxis(1, 1);      // Range Axis

    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setUpperBound(Math.max(expectedTotalScope, yaxisMaxValue) +100);
    rangeAxis.setLowerBound(0.);
    rangeAxis.setVisible(false);

    // Dashed line
    LineAndShapeRenderer lineAndShapeRenderer = new LineAndShapeRenderer(true, true);
    lineAndShapeRenderer.setSeriesPaint(0,Color.black);
    lineAndShapeRenderer.setBaseItemLabelsVisible(Boolean.TRUE);
    lineAndShapeRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());

    plot.setRenderer(lineAndShapeRenderer);
}}
Alumbo
  • 21
  • 3
  • Have you looked at `SymbolAxis`, seen [here](https://stackoverflow.com/search?tab=votes&q=%5bjfreechart%5d%20SymbolAxis)? – trashgod May 02 '22 at 18:26
  • Hi, thanks for your response. My problem is that the Timeline Axis does not show, I want a second Domain Axis. – Alumbo May 03 '22 at 07:53
  • Can you verify your `mapDatasetToDomainAxis` parameters, for [example](https://stackoverflow.com/q/15025434/230513)? – trashgod May 03 '22 at 12:19
  • Actually it works! I do have the timeline axis. In fact I'm using a multiAxis chart with multiple chartCustomizers so I had to replicate this sprint axis to all of them. Now I need to add a labels to my axis to finish the timeline. – Alumbo May 06 '22 at 14:09
  • You can [answer your own question](http://meta.stackoverflow.com/q/17463/163188) going forward. – trashgod May 06 '22 at 18:35
  • I have one problem left. It is not possible to use a SymbolAxis with a category plot. – Alumbo May 10 '22 at 12:56
  • Maybe a `CategoryMarker`? – trashgod May 10 '22 at 15:22

0 Answers0