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
);