获取折线图系列描边颜色

时间:2019-06-25 14:48:17

标签: javafx charts

这是此问题的后续解答:How to get the color from a series in JavaFX Chart and assign it to a checkbox,有0个答案。

我想获得LineChart系列笔触生成的颜色,以便将其设置为复选框的文本颜色。

这是我的示例代码(折线图取自Oracle教程):

{this.props.tabsDivIframe.map((url, index) =>
    <div key={url.toString() id={"myTab" + index}>
    {( this.props.tabsiframe === 'si') //this line here; we share this same value for all tabs
        ? (
            <iframe title={"iframe"+index} className="iframeTab" src={url}></iframe>
        ) : (
            <div>{url}</div>
    )}
    </div>
)}  

我试图将系列样式类添加到复选框样式类中(如Getting series color from LineChart中的建议):

public class LineChartSample extends Application {

    @Override
    public void start(Stage stage) {

        HBox box = new HBox();

        stage.setTitle("Line Chart Sample");
        final NumberAxis xAxis = new NumberAxis();
        final NumberAxis yAxis = new NumberAxis();
        xAxis.setLabel("Number of Month");
        final LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);

        lineChart.setTitle("Stock Monitoring, 2010");
        XYChart.Series series = new XYChart.Series();
        series.setName("My portfolio");
        series.getData().add(new XYChart.Data(1, 23));
        series.getData().add(new XYChart.Data(2, 14));
        series.getData().add(new XYChart.Data(3, 15));
        series.getData().add(new XYChart.Data(4, 24));
        series.getData().add(new XYChart.Data(5, 34));
        series.getData().add(new XYChart.Data(6, 36));
        series.getData().add(new XYChart.Data(7, 22));
        series.getData().add(new XYChart.Data(8, 45));
        series.getData().add(new XYChart.Data(9, 43));
        series.getData().add(new XYChart.Data(10, 17));
        series.getData().add(new XYChart.Data(11, 29));
        series.getData().add(new XYChart.Data(12, 25));

        lineChart.getData().add(series);

        CheckBox test = new CheckBox("test");

        test.setStyle("-fx-text-fill: <series color>;");

        box.getChildren().addAll(lineChart, test);

        Scene scene = new Scene(box, 800, 600);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

其中系列样式类是具有以下值的列表:chart-series-line,series0和default-color0,但是它不起作用。

预先感谢您的帮助。

0 个答案:

没有答案