簡體   English   中英

JavaFX圖表將NumberAxis更改為CategoryAxis

[英]Javafx chart change NumberAxis to CategoryAxis

我已經創建了一個AreaChart與SceneBuilder NumberAxis上的X軸和NumberAxis在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 因為我必須制作一個Heigth x Distance圖表,然后按一個按鈕將該圖表轉換為Height x Time圖表,並且按下按鈕后的結果必須是:

<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>

我認為更改嘗試更改圖表的軸類型不是一個好主意(我什至不確定是否可以這樣做)。

相反,我建議:

  1. 創建兩個圖表。
  2. 一種使用CategoryAxis,另一種使用NumberAxis。
  3. 向兩個圖表添加相似的數據(但可能不同)系列。
  4. 將兩個圖表都放在StackPane中。
  5. 添加ToggleButtonToggleSwitchCheckBoxRadioButton (某種切換控件),以在兩種狀態之間切換。
  6. 將一個圖表的可見性綁定到切換的選定狀態,並將另一圖表的可見性綁定到未切換的選定狀態。

這樣可以使您根據需要顯示具有適當軸類型的適當圖表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM