- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想更新 LineChart 图例的样式,我在具有相应系列类的节点上使用 setStyle。
String color = ....
XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
_chart.getData().add(series);
String seriesClass = null;
for(String styleClass : series.getNode().getStyleClass())
{
if(styleClass.startsWith("series"))
{
seriesClass = styleClass;
break;
}
}
if(seriesClass != null)
{
//
// Customize the style.
//
StringBuilder sb = new StringBuilder();
sb.append("-fx-stroke: ");
sb.append(color);
sb.append("; ");
sb.append("-fx-background-color: ");
sb.append(color);
sb.append(", white;");
if(doted)
{
sb.append("-fx-stroke-dash-array: 10 10");
}
_styles.put(seriesClass, sb.toString());
}
java.util.Set<javafx.scene.Node> nodes = _chart.lookupAll("." + seriesClass);
for(javafx.scene.Node n : nodes)
{
n.setStyle(style);
}
问题是,这只会影响路径的样式,图例样式不会改变。我已经打印了图表节点子节点,并发现在添加系列调用返回后,图例尚未完全创建:
Legend@18e8627[styleClass=chart-legend]
Label@1689c98[styleClass=label chart-legend-item]
Label@100e4ce[styleClass=label chart-legend-item]
Label@1adcb5e[styleClass=label chart-legend-item]
Label@102a8fb[styleClass=label chart-legend-item]
稍后如果我再次打印子项:
Legend@9a095[styleClass=chart-legend]
Label[id=null, styleClass=label chart-legend-item]
LabelSkin[id=null, styleClass=label chart-legend-item]
Region@12acafc[styleClass=chart-legend-item-symbol chart-line-symbol series0 default-color0]
LabeledText@749a47[styleClass=text]
Label[id=null, styleClass=label chart-legend-item]
LabelSkin[id=null, styleClass=label chart-legend-item]
Region@3ca3a4[styleClass=chart-legend-item-symbol chart-line-symbol series1 default-color1]
LabeledText@11b9972[styleClass=text]
Label[id=null, styleClass=label chart-legend-item]
LabelSkin[id=null, styleClass=label chart-legend-item]
Region@57f433[styleClass=chart-legend-item-symbol chart-line-symbol series2 default-color2]
LabeledText@6172b5[styleClass=text]
Label[id=null, styleClass=label chart-legend-item]
LabelSkin[id=null, styleClass=label chart-legend-item]
Region@16458ed[styleClass=chart-legend-item-symbol chart-line-symbol series3 default-color3]
LabeledText@10a68bd[styleClass=text]
如果我现在更新样式,图例样式会正确更新。
我如何知道何时添加了具有设置样式所需的类的 Region 子项,以便我可以在该节点上设置样式?
添加新系列时更新图例样式还有其他想法吗?
最佳答案
我也遇到了这个问题。想出了一个解决方法,可以检测图例项何时创建,以便可以向它们添加动态样式。
我向图例的“getChildrenUnmodifying()”ObservableList 添加了一个 ListChangeListener,这又在添加图例的每个子项时向其添加一个 ListChangeListener。从这个监听器中,我们可以知道何时将新项目添加到图例中(或删除)。这使我们能够进行动态样式更改。
for (Node n : lineChart.getChildrenUnmodifiable())
{
if (n instanceof Legend)
{
final Legend legend = (Legend) n;
// remove the legend
legend.getChildrenUnmodifiable().addListener(new ListChangeListener<Object>()
{
@Override
public void onChanged(Change<?> arg0)
{
for (Node node : legend.getChildrenUnmodifiable())
{
if (node instanceof Label)
{
final Label label = (Label) node;
label.getChildrenUnmodifiable().addListener(new ListChangeListener<Object>()
{
@Override
public void onChanged(Change<?> arg0)
{
//make style changes here
}
});
}
}
}
});
}
}
关于JavaFX LineChart 图例样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12197877/
我正在尝试使用立方图制作 LineChart。结果如下面的截图所示:三次贝塞尔曲线显示错误并有“尖峰”。有人可以帮我让它正确显示吗? 这是我的配置: LineDataSet lineD
Tag Library supports namespace: http://primefaces. org/ui,但没有为名称定义标签:lineChart
我想使用 primefaces 5.1 创建折线图。但在加载我的 xhtml 页面时,我收到错误消息“ Tag Library supports namespace: http://primeface
默认情况下,在 chart.js 中显示折线图时.工具提示显示存在的所有数据集的值。 当我们将鼠标悬停在该数据集点而不是所有数据集点上时,如何仅显示一个数据集点的值 最佳答案 nearest工具提示选
这个图表显示了问题: 我有计算数据和绘制图表的 JavaFX 程序,但为什么点连接不正确?我尝试了很多东西,甚至创建了两个单独的系列,但它不起作用。 public void createScatter
我知道在 Using Google Visualization API, how to turn off tooltips for a single column? 之前已经问过这个问题,但我没有得到
我想更新 LineChart 图例的样式,我在具有相应系列类的节点上使用 setStyle。 String color = .... XYChart.Series series = new XYCha
这是界面代码: @Override public void start(Stage primaryStage){ NumberAxis xAxis = new NumberAxis();
这个问题已经有答案了: JavaFX BarChart, Set Series Color by Series Name (1 个回答) 已关闭 5 年前。 此帖子已于 7 个月前编辑并提交审核,但未
我在从折线图中删除数据时遇到问题。我写了一个绘制图表的程序,点击按钮后的 Action 完成图表数据。 dataSeries1.getData().removeAll(); () {
我有这个代码: @Override public void start(Stage primaryStage){ NumberAxis xAxis = new NumberAxis();
刚刚遇到了 javafx.scene.chart.LineChart 的问题。当使用高于 5E13 的 Double 值填充图表数据时,该系列恰好消失(参见屏幕截图)。 之前 之后 以防万一:我使用以
我正在尝试将 javaFX LineChart 保存为 PNG,我希望背景是透明的。如果我这样做: SnapshotParameters spa = new SnapshotParameters();
我正在尝试使用 JavaFX 中的 LineChart 向用户显示数据。我有一个 Float 数组(不是原语,是对象,如 Float[] 中所示),可以随时添加,长度可以在 512 到 4096 点之
我正在尝试在 JavaFX 中创建折线图。此折线图应该有一个轴 (y) 与数字和另一个轴 (x) 与日期。日期范围应该由用户使用两个日期选择器来选择。现在这是我的问题:折线图只有类别和数字轴。有什么方
我正在使用这个图表库 https://github.com/danielgindi/Charts在我的申请中。我从中实现了折线图,图例相互重叠。我不确定这里出了什么问题,我确实玩过很多传奇的不同属性,
我正在使用 javascript 在我的 Web 应用程序中显示 Google Visulization LineChart。我怎样才能让它显示垂直网格线?我已经阅读了有关使用 chg 设置它们的信息
我想使用 Recharts 的 LineChart 来显示最多 200 个点的数据集。但是,我只想在小屏幕上显示其中 5 个数据点的点/工具提示/activeDot,因为在智能手机上不再可点击 200
我想在 LineChart 中设置一些值,但出现错误:添加了重复系列,或 NPE(我尝试清除我的系列列表,调用retainAll,但没有任何结果有帮助)在我的 Controller 类中,我存储了我的
我有一个关于图表 LineChart JavaFX 的好奇问题。 我有这个图表: 在 X 轴上形成“跳跃”的点(如我得分的两个红点所示),因此 JavaFX 在这两点之间画了一条线。如何删除每个“跳转
在这个演示中 http://nvd3.org/livecode/index.html#codemirrorNav只需将数据更改为 function() { return [ {
我是一名优秀的程序员,十分优秀!