[英]How to convert X, Y data-types to double value in JavaFX?
我正在使用JavaFX,並且正在創建一個通用LineChart,它可以向Axis接收“字符串”或“數字”數據類型,但是我使用的數據類型X,Y有問題,因為在向圖表添加數據的方法,我有兩個通用參數X和Y,我需要將“ Y”轉換為“ double”,因為當我使用此方法時,Y參數是“ double”值,但是我無法再次轉換“ Y”值改為“ double”。
添加數據的方法是:
public void addData(final String idSeries, final X x, final Y y, String kindOfSymbol) {
//valido que exista la serie
boolean seriesExist = seriesMap.containsKey(idSeries);
//obtengo el index de la serie, como fue almacenada en la grafica
Integer indexSerie = seriesMap.get(idSeries);
if (seriesExist) {
Platform.runLater(() - > {
XYChart.Series < X, Y > currentSeries = null;
currentSeries = chart.getData().get(indexSerie.intValue());
int lastNodePosition = currentSeries.getData().size() - 1;
XYChart.Data < X, Y > point = new XYChart.Data < > (x, y);
//The problem is here when I try to convert "Y" to "double" because the object JFXStackPaneSymbol require the double and Dimension parameters
point.setNode(new JFXStackPaneSymbol(y, new Dimension(15, 15)));
currentSeries.getData().add(point);
currentSeries.getData().get(lastNodePosition).getNode().setStyle(kindOfSymbol);
});
}
}
方法調用是:
lineChart.addData(Constants.ID_LINE_SERIE, xAxisUnit++, value, tempSymbol);
//Constants.ID_LINE_SERIE = String
//xAxisUnit++ = double
//value = double
//tempSymbol = String
非常感謝您的幫助。
解決方案是:
Double.parseDouble(y.toString())
在代碼中是:
point.setNode(new JFXStackPaneSymbol(Double.parseDouble(y.toString()), new Dimension(15, 15)));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.