Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart with inverted y axis

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.

Inverted Y-Axis with positive numbers

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."

like image 602
mawcsco Avatar asked Aug 02 '13 21:08

mawcsco


People also ask

How do you reverse the Y axis?

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.

How do I flip the axis in an Excel chart?

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.

How do you flip two Y axis in Excel?

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.


1 Answers

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));
like image 54
Sergey Grinev Avatar answered Oct 11 '22 14:10

Sergey Grinev