我有两组数据
int[] x1 = {1,2,3,4,5,6,7,8,9,10};
int[] y1 = {1,2,3,5,6,8,9,10,14,11};
int[] x2 = {1,2,3,4,5,6,7,8,9,10};
int[] y2 = {0,2,3,5,0,8,9,8,14,11};
int[] z2 = {1,2,3,1,2,3,1,2,3,1};
我想将其绘制x1,y1
为一个XYLineChart
,然后将其绘制x2,y2
为同一个图上的散点图,没有一条线。
我还需要每个散点为xy,y2
不同的颜色,具体取决于z2
(1=Color.red, 2=Color.green, 3=Color.blue)
我怎样才能做到这一点?
到目前为止,我有:
JPanel panel_1 = new JPanel();
panel_1.setLayout(new BorderLayout(0, 0));
XYSeriesCollection dataset = new XYSeriesCollection();
XYSeries series1 = new XYSeries("series1");
for(int i=0; i<x1.length; i++){
series1.add(x1[i],y1[i]);
}
dataset.add(series1);
JFreeChart chart = ChartFactory.createXYLineChart("Title", "x", "y", dataset, PlotOrientation.VERTICAL, false, false, false);
ChartPanel cp = new ChartPanel(chart);
panel_1.add(cp, BorderLayout.CENTER);
这使折线图排序。x2,y2
我现在需要为我卡住的散点图(使用上述颜色)编写代码。