【问题标题】:Javafx chart change NumberAxis to CategoryAxisJavafx 图表将 NumberAxis 更改为 CategoryAxis
【发布时间】:2016-05-23 14:51:34
【问题描述】:

我使用 SceneBuilder 创建了一个 AreaChart,X 轴上带有 NumberAxisNumberAxis 在 Y 轴上。

@FXML
private  AreaChart<Number,Number> areaChart;

和 FXML:

<AreaChart fx:id="areaChart" alternativeColumnFillVisible="true" createSymbols="false" style="-fx-horizontal-grid-lines-color: white;" title="Altura durante la sesión">
    <xAxis>
        <NumberAxis fx:id="areaX" animated="false" label="Distancia (metros)"    style="axis_color: white;" />
    </xAxis>
    <yAxis>
        <NumberAxis fx:id="areaY" label="Altura (metros)" style="axis_color:    white;" />
    </yAxis>

我想通过按下按钮将该 areaChart 转换为 AreaChart,在 Y 轴上带有 NumberAxis,在 X 轴上带有 CategoryAxis。 因为我必须制作一个高度 x 距离图表,然后按一个按钮将该图表转换为高度 x 时间图表 按下按钮后的结果应该是这样的:

<AreaChart fx:id="areaChart" alternativeColumnFillVisible="true" createSymbols="false" style="-fx-horizontal-grid-lines-color: white;" title="Altura durante la sesión">
    <xAxis>
        <CategoryAxis fx:id="areaX" animated="false" label="Distancia (metros)"    style="axis_color: white;" />
    </xAxis>
    <yAxis>
        <NumberAxis fx:id="areaY" label="Altura (metros)" style="axis_color:    white;" />
    </yAxis>

【问题讨论】:

    标签: java javafx charts fxml scenebuilder


    【解决方案1】:

    我不认为改变尝试改变图表的轴类型是一个好主意(我什至不确定你是否可以这样做)。

    相反,我建议:

    1. 创建两个图表。
    2. 一种使用 CategoryAxis,另一种使用 NumberAxis。
    3. 将相似的数据(但可能不同)系列添加到两个图表中。
    4. 将两个图表放入 StackPane。
    5. 添加ToggleButtonToggleSwitchCheckBoxRadioButton(某种切换控件),以在两种状态之间切换。
    6. 将一个图表的可见性绑定到切换的选定状态,并将另一个图表的可见性绑定到非切换的选定状态。

    这应该允许您根据需要显示具有适当轴类型的适当图表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      • 1970-01-01
      • 2018-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多