简体   繁体   English

JavaFX 8 SceneBuilder LineChart数据类型

[英]JavaFX 8 SceneBuilder LineChart data type

It seems like when I create a LineChart in SceneBuilder it defaults to "String". 好像当我在SceneBuilder中创建一个LineChart时,它默认为“ String”。 That is: LineChart<String, String> . 即: LineChart<String, String>

When I load it in code then try to add some data I get: 当我在代码中加载它时,尝试添加一些数据:

Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String

It works fine if I create the chart in code instead: 如果我用代码创建图表,则效果很好:

val chart = new LineChart[Number, Number]( new NumberAxis(), new NumberAxis())

I don't see any option in SceneBuilder that allows me to choose "Number" as the type of data the chart will have. 我在SceneBuilder中看不到任何允许我选择“数字”作为图表将具有的数据类型的选项。

What am I missing here? 我在这里想念什么?

Just edit the FXML generated by SceneBuilder in a text editor, for example, if you create a new LineChart in SceneBuilder 2, it will generate the following FXML: 只需在文本编辑器中编辑SceneBuilder生成的FXML,例如,如果在SceneBuilder 2中创建新的LineChart,它将生成以下FXML:

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.chart.*?>

<LineChart xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:id="xychart">
  <xAxis>
    <CategoryAxis fx:id="xAxis" side="BOTTOM" />
  </xAxis>
  <yAxis>
    <NumberAxis fx:id="yAxis" side="LEFT" />
  </yAxis>
</LineChart>

Edit it to change the line: 编辑它以更改行:

<CategoryAxis fx:id="xAxis" side="BOTTOM" />

to: 至:

<NumberAxis fx:id="xAxis" side="BOTTOM" />

The chart will automatically reload in SceneBuilder (because it watches for edits to the FXML file) to include two number axes instead of a NumberAxis and a CategoryAxis. 该图表将自动重新加载到SceneBuilder中(因为它监视对FXML文件的编辑),以包括两个数字轴,而不是NumberAxis和CategoryAxis。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM