Using JavaFX Charts, I need to invert the y-axis of a stacked area chart so that a positive zero is at the top and the positive numbers work downward on the y-axis. Below is a mock-up of what I'm trying to achieve.
What is the best (read: shortest development time and high code-reuse) way to achieve this in JavaFX?
UPDATE
Converting the data to negative numbers is not an option. I'm looking for answers that will work with the positive numbers, "untouched."
To do this, we have to right click the y axis that we want to reverse. Then, select the Format Axis from the context menu. The next thing to do is to check the Categories in reverse order. This is found in the Format Axis dialog, in the Axis Options.
Change the way that data is plotted Click anywhere in the chart that contains the data series that you want to plot on different axes. This displays the Chart Tools, adding the Design, Layout, and Format tabs. On the Design tab, in the Data group, click Switch Row/Column.
To change the display of the secondary vertical axis, do the following: On the Layout tab, in the Axes group, click Axes. Click Secondary Vertical Axis, and then click the display option that you want.
You can use regular axis with negative values, but add TickLabelFormatter
which will strip minus sign.
final NumberAxis yAxis = new NumberAxis(-25, 0, 5);
yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis) {
@Override
public String toString(Number value) {
// note we are printing minus value
return String.format("%7.1f", -value.doubleValue());
}
});
series1.getData().add(new XYChart.Data("Jan", -1));
series1.getData().add(new XYChart.Data("Feb", -5));
series1.getData().add(new XYChart.Data("Mar", -20));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With