我有一个由x和y值组成的小数据集=> x:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14, 15]和 y:[10、5、6、7、11、2、7、7、8、9、10、1、9、15、14、15] 我正在使用JFreeChart绘制这些值。我想用不同的颜色标记点[{5,2} {10,10} {14,14}],因为线的颜色当前设置为蓝色。如何以不同的颜色突出显示这些点(可能是这些点的圆/椭圆)并另存为JPEG / PNG。
下面是我编写的代码
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
public class Main {
public static void main(String[] args) {
Demo demo = new Demo();
demo.plot();
}
}
class Demo {
private XYSeries xyseries = null;
private XYDataset xyDataSet = null;
private JFreeChart chart = null;
private List<Integer> xList = null;
private List<Integer> yList = null;
public void plot() {
try {
xList = new ArrayList<Integer>();
xList = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
yList = new ArrayList<Integer>();
yList = Arrays.asList(10, 5, 6, 7, 11, 2, 7, 7, 8, 9, 10, 1, 9, 15, 14, 15);
xyseries = new XYSeries("SCR");
for (int i = 0; i < xList.size(); i++) {
xyseries.add(xList.get(i), yList.get(i));
}
xyDataSet = new XYSeriesCollection(xyseries);
chart = ChartFactory.createXYLineChart("Demo", "X", "Y", xyDataSet, PlotOrientation.VERTICAL, true, true,
false);
chart.getXYPlot().getRenderer().setSeriesPaint(0, Color.BLUE);
chart.getPlot().setBackgroundPaint(Color.WHITE);
ChartUtilities.saveChartAsJPEG(new
File("C:\\Users\\krishna\\Desktop\\demo\\demo.jpeg"), chart, 500, 400);
} catch (IOException e) {
e.printStackTrace();
}
}
}