-
Notifications
You must be signed in to change notification settings - Fork 398
Open
Labels
Description
I have the following chart and I want to hide every 2 tick labels on the x-axis.
The expected output should be:
I used the setxAxisTickLabelsFormattingFunction
method as follows:
import org.knowm.xchart.QuickChart;
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.XYChart;
public class App {
public static void main(String[] args) throws Exception {
double[] yData = new double[] { 100, 90, 90, 89, 80, 101, 102, 99 };
// Create Chart
XYChart chart = QuickChart.getChart("Sample Chart", "X", "Y", "y(x)", null, yData);
// hide every 2 xtick labels
chart.getStyler().setxAxisTickLabelsFormattingFunction(x -> x.intValue() % 2 == 0 ? String.valueOf(x) : " ");
// Show it
new SwingWrapper(chart).displayChart();
}
}
The resulting incorrect chart is:
If I change the formatting function to x -> x.intValue() % 2 == 0 ? String.valueOf(x) : "skip"
, the resulting chart becomes:
It seems that there are only 2 unique values of x
that are passed to the formatting function instead of 8.
How can I achieve my desired output? Thanks.
Note: I am using xchart-3.8.5.jar
.