【问题标题】:Get series names from LineChart object从 LineChart 对象获取系列名称
【发布时间】:2015-08-07 03:20:08
【问题描述】:

例如,我创建了Linechart 并以这种方式添加了系列:

LineChart lineChart = new LineChart();
XYChart.Series series = new XYChart.Series();
series1.getData().add("Name1", xValue1[], yValue1[]);
series2.getData().add("Name2", xValue2[], yValue2[]);
lineChart.getData().add(series1);
lineChart.getData().add(series2);

如果之后我将 lineChart 发送到其他类,我如何从那里使用 lineChart 对象获取系列名称(Name1Name2)?

【问题讨论】:

    标签: java javafx javafx-8 linechart series


    【解决方案1】:

    尝试使用:

    for(XYChart.Series series : lineChart.getData()) {
        series.getName();
    }
    

    【讨论】:

    • 对不起,我不明白。它们也不同:系列和对象。
    • lineChart.getData() 将始终返回一个系列。你的意思是他们有不同的类型?
    • IDEA says that they are different 。 baseChart 是:LineChart baseChart;
    • 这个错误是因为你的 LineChart 没有类型。您可以声明 LineChart<String, Number> baseChart 或您使用的任何类型。您还可以通过声明 ObservableList<Series> list = lineChart.getData(); 并在 list 上运行循环来键入您的列表。
    • 非常感谢。决定是: ObservableList lists = baseChart.getData(); for (XYChart.Series list : lists) { list.getName(); }
    猜你喜欢
    • 2015-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-13
    • 2019-07-30
    • 1970-01-01
    相关资源
    最近更新 更多