Help on FX 2.x

susieferrari

Mitglied
Hi good morning,

I am new to this forum just registered (many thanks to Google translate!), I do not speak german so I hope it doesn't mind if I write in english.

I am facing some problems with JavaFx 2.x so I hope to get help from this community.

I have no idea how to set logarithmic Y axis for a XY Line chart

Below is a sample code to plot a linear data

Code:
public class BaseXYChart extends Application {

    @Override
    public void start(Stage stage) {
       stage.setTitle("Linear plot");
        
       final CategoryAxis xAxis = new CategoryAxis();
       final NumberAxis yAxis = new NumberAxis(0, 22, 0.5);
        
       yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis){
            @Override
        public String toString(Number object){
            return String.format("%7.2f", object);
        }
    });
final LineChart<String, Number>lineChart = new LineChart<String, Number>(xAxis, yAxis);

       lineChart.setCreateSymbols(false);
       lineChart.setAlternativeRowFillVisible(false);
       lineChart.setLegendVisible(false);
               
       XYChart.Series series1 = new XYChart.Series();
        
        series1.getData().add(new XYChart.Data("Jan", 1));
        series1.getData().add(new XYChart.Data("Feb", 1.5));
        series1.getData().add(new XYChart.Data("Mar", 2));
        series1.getData().add(new XYChart.Data("Apr", 2.5));
        series1.getData().add(new XYChart.Data("May", 3));
        series1.getData().add(new XYChart.Data("Jun", 4));
        series1.getData().add(new XYChart.Data("Jul", 6));
        series1.getData().add(new XYChart.Data("Aug", 9));
        series1.getData().add(new XYChart.Data("Sep", 12));
        series1.getData().add(new XYChart.Data("Oct", 15));
        series1.getData().add(new XYChart.Data("Nov", 20));
        series1.getData().add(new XYChart.Data("Dec", 22));
 
        BorderPane pane = new BorderPane();
        pane.setCenter(lineChart);          
        Scene scene = new Scene(pane, 800, 600);
        lineChart.getData().addAll(series1);
         
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }   
}

Would someone be so kind to change this code to get a log plot? I haven't find any example anywhere on the net!

Thank you very much!

Susie
 

susieferrari

Mitglied
Thanks Flown,

this was the only example I found but it is in JavaScript and it doesn't works even if adapted for Fx 2.x

I think it must specifically written for Fx 2.x, that's the reason for asking help here.

Regards,

Susie
 

Flown

Administrator
Mitarbeiter
But this is a solution for your problem. You have to implement valueaxis on your own. The solution is written in javascript but the calculations remain the same.
 

Ähnliche Java Themen

Neue Themen


Oben