JavaFX折线图颜色差异 [英] JavaFX Linechart Color differences
本文介绍了JavaFX折线图颜色差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在JavaFx中有一个带有两条线的线图,我想为线之间的空间着色。我搜索了互联网,但没有找到任何东西。
这就是我所拥有的:
我希望它看起来像:
解决方案
感谢来自
I have a Line Graph in JavaFx with two Lines and I want to color the Space between the Lines. I Searched the Internet but did not find anything. This is what i have:
And I want it to look like:
解决方案
Thanks to a Comment from NwDx I was able to solve my Problem.
I overrited the layoutPlotChildren()
of Chart
like this :
super.layoutPlotChildren();
XYChart.Series s = (XYChart.Series) getData().get(0);
XYChart.Series d = (XYChart.Series) getData().get(1);
ObservableList<XYChart.Data<X,Y>> systole = s.getData();
ObservableList<XYChart.Data<X,Y>> diastole = d.getData();
for(int i = 0; i < systole.size()-1; i++)
{
XYChart.Data SysPoint = systole.get(i);
XYChart.Data DiasPoint = diastole.get(i);
double x = getXAxis().getDisplayPosition(SysPoint.getXValue().toString());
double y = getYAxis().getDisplayPosition(DiasPoint.getYValue());
double x2 = getXAxis().getDisplayPosition(systole.get((i+1)).getXValue().toString());
double y2 = getYAxis().getDisplayPosition(diastole.get((i+1)).getYValue());
Polygon polygon = new Polygon();
LinearGradient linearGrad = new LinearGradient(
0, // start X
0, // start Y
0, // end X
1, // end Y
true, // proportional
CycleMethod.NO_CYCLE, // cycle colors
// stops
new Stop(0.1f, Color.rgb(255, 0, 0, .3)),
new Stop(0.5f, Color.rgb(127, 0, 127, .3)),
new Stop(1.0f, Color.rgb(0, 0, 255, .3)));
polygon.getPoints().addAll(new Double[]{
x,y,
x, getYAxis().getDisplayPosition(SysPoint.getYValue()),
x2,getYAxis().getDisplayPosition(systole.get((i+1)).getYValue()),
x2,y2
});
getPlotChildren().add(polygon);
polygon.toFront();
polygon.setFill(linearGrad);
}
}
I create a Polygon wich connects two Systole and two Diastole Points and fill them with a LinearGradient.
My Chart now looks like:
这篇关于JavaFX折线图颜色差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文