JavaFX XYChart对数图 [英] JavaFX XYChart Logarithmic plot

查看:59
本文介绍了JavaFX XYChart对数图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XYChart将数据绘制为Y轴上的线性步长,我想绘制为对数或半对数的Y刻度,如何更改我的以下代码?

I have a XYChart plotting data as linear steps on Y axis, I would like to plot as logarithmic or semi-logarithmic Y scale, how to change my following 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(1, 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);

   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);
}

}

谢谢

推荐答案

我认为JavaFX Vanilla中不可能.但您可以在这里看看: http://blog .dooapp.com/2013/06/logarithmic-scale-strikes-back-in.html

I think it's not possible in JavaFX Vanilla. But you can take a look here : http://blog.dooapp.com/2013/06/logarithmic-scale-strikes-back-in.html

这篇关于JavaFX XYChart对数图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆