我有两组数据。
我希望绘制
我还需要使
我应该怎么做?
到目前为止,我的代码是:
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
(带有上述描述的颜色),这是我卡住的地方。