gpt4 book ai didi

java 如何对 JFreeChart AreaChart 进行渐变绘制

转载 作者:行者123 更新时间:2023-11-29 08:56:48 32 4
gpt4 key购买 nike

public static JFreeChart createAreaChart(double[] v1) {
XYSeriesCollection dataset = new XYSeriesCollection();
XYSeries series1 = new XYSeries("First");
for (int i=0;i<v1.length;i++){
series1.add( i,v1[i]);
}
dataset.addSeries(series1);

final JFreeChart chart = ChartFactory.createXYAreaChart(
"XY Area Chart Demo",
"Domain (X)", "Range (Y)",
dataset,
PlotOrientation.VERTICAL,
true, // legend
true, // tool tips
false // URLs
);

GradientPaint gp0 = new GradientPaint(
0.0f, 0.0f, Color.red,
0.0f, 100.0f, Color.blue
);

chart.setBackgroundPaint(Color.white);

final XYPlot plot = chart.getXYPlot();
plot.getRenderer().setSeriesPaint(0, gp0);
//plot.setOutlinePaint(Color.black);
plot.setBackgroundPaint(Color.lightGray);
plot.setForegroundAlpha(0.99f);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);

final ValueAxis domainAxis = plot.getDomainAxis();
domainAxis.setTickMarkPaint(Color.black);
domainAxis.setLowerMargin(0.0);
domainAxis.setUpperMargin(0.0);

final ValueAxis rangeAxis = plot.getRangeAxis();
rangeAxis.setTickMarkPaint(Color.black);
rangeAxis.setAutoRange(false);
rangeAxis.setRange(-5.0, 5.0);

return chart;

}

我想要下面这样的东西。当我们越过零线时缓慢切换颜色的渐变填充。

我不明白我应该输入什么:

    GradientPaint gp0 = new GradientPaint(
0.0f, 0.0f, Color.red,
0.0f, 100.0f, Color.blue
);

enter image description here

最佳答案

做到这一点的最佳方法是拥有 3 个形状。一个用于黄线。另一个用于绿色渐变,第三个用于红色渐变。

然后独立绘制最后两个形状。

关于java 如何对 JFreeChart AreaChart 进行渐变绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19929631/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com