Search code examples
javachartsscalejfreechartbar-chart

LayeredBar Chart using JFreeChart Scale with minimum labels


I am trying to plot a graph, Where I want Y axis with Major Labels and Minor scales with out label of the range.

NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
yAxis.setTickUnit(new NumberTickUnit(1));
yAxis.setAutoRange(true);
yAxis.setAutoRangeMinimumSize(height);

using above code I'm getting a plot with all Labels overlapping. But I required a chart as below where chart has scale same as ruler has i.e. Major scale with label and minor scale without label

Please help?


Solution

  • JFreeChart does have support for minor tick marks:

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setMinorTickMarksVisible(true);
    plot.setRangeMinorGridlinesVisible(true);
    

    If you want to change the number of minor tick marks, then you have to create a custom TickUnitSource if you want to retain the auto-tick-unit-selection feature.