1

I've trying to find a solution to this problem. I have an XYLineChart and I would like to have uneven spaces between tick units.

This is what I have

This is what I´m trying to achieve

This is my code:

//Method (receive the dataset and return the chart)
private JFreeChart createChart(XYDataset dataset){

    //--------create XYlineChart
    JFreeChart oChart = ChartFactory.createXYLineChart("XYLineChart", "X", "Y", dataset);
    XYPlot plot = (XYPlot) oChart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);

    // render shapes and lines
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
    plot.setRenderer(renderer);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setNumberFormatOverride(THOUSANDS);   //Override and Use a my NumberFormat
    xAxis.setRange(0, 8000);
    //I want to use this with my own set of tickUnits, the values(x) that are on the image I'm trying to achieve
    //xAxis.setStandardTickUnits(); 
    xAxis.setTickUnit(new NumberTickUnit(500));
    
    yAxis.setRange(0.0, 130.0);
    yAxis.setTickUnit(new NumberTickUnit(10));
    yAxis.setInverted(true);
    
    return oChart;
}

I dont know how to make my own set of TickUnits or how to space the domainAxis (xAxis) unevenly.

I'll be glad to read any examples of something like that, so i can try to use it or apply it.

I'll really appreciate your help, is the only thing missing in my project.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1
    Maybe a `LogAxis` with a custom base, for [example](https://stackoverflow.com/a/10353270/230513)? – trashgod Feb 25 '21 at 14:02
  • I used the `LogAxis` as you suggested, I didn't get the exact results but with a base(2) I'm close enough to what I wanted. (I'm still wondering if is possible to get the results that base(2) is missing though). Either way, Thank you so much. – Carlos Viera Feb 26 '21 at 21:34
  • More [here](https://medium.com/biovinci/log-base-2-or-e-or-10-9f2a694faa51). – trashgod Feb 26 '21 at 22:32

0 Answers0