如何设置JavaFX XYChart.Series的特定颜色? [英] How to set specific color to JavaFX XYChart.Series?

查看:288
本文介绍了如何设置JavaFX XYChart.Series的特定颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置JavaFX折线图的样式,但是找不到任何将颜色设置为特定系列的方法.我知道,我可以通过CSS设置样式,但是找不到如何为我的系列设置ID或CLASS.

I am trying to style my JavaFX linechart, but can't find any way to set color to specific series. I know, that I can style via CSS, but I can't find how to set ID or CLASS to my series.

任何人都可以给我一个线索:

Can anyone give me a clue on:

  1. 如何为折线图设置颜色?
  2. 如何将CSS类设置为series?

推荐答案

通常,样式表的首选方式是不使用代码,而是按照jschoen的建议仅使用css样式表.此外,如果需要进一步的自定义,则可以使用代码中的css查找来挖掘从序列数据生成的节点,并应用各种其他css样式.

In general the way preferred way to style charts is without code, using only css stylesheets as jschoen recommends. Additionally, if further customization is required, you can use css lookups from code to dig into the the nodes generated from series data and apply various additional css styling.

以下是有关动态更改示例程序,以给出答案.在示例应用程序中,所有其他CSS样式都是通过代码中的setStyle调用完成的.使用类似的查找技术,您可以访问系列节点以应用适当的样式表样式类,而不是setStyle调用.

Here is information about dynamically changing a JavaFX line chart style and a sample program to go with the answer. In the sample app, all of the additional css styling is done via a setStyle call from code. Using a similar lookup technique, you could get access to the series nodes to apply an appropriate stylesheet styleclass rather than a setStyle call.

这篇关于如何设置JavaFX XYChart.Series的特定颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆