我需要绘制一个散点图,但是像类中的所有点一样,类别应该是红色的,或者点形状可以是正方形,以区别于b类点,但我也不希望这些点被加入XYPlot中的行。我已经搜索过它而无法找到答案,所以如果您发现这是一个重复的问题,那么请指导我原创。感谢
答案 0 :(得分:0)
我玩散点图并且能够解决问题。以下代码解决了它。 setupData()将类名作为输入,并基本对其进行分类。我之前没有看到。我希望它可以帮助那些面临同样问题的人。
package graph.generator;
import java.util.ArrayList;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
public class GenerateScatterPlot extends ApplicationFrame{
static XYSeriesCollection dataset;
public GenerateScatterPlot(String applicationTitle) {
super(applicationTitle);
JFreeChart chart = ChartFactory.createScatterPlot("Coordinates", "X", "Y", setupData(), PlotOrientation.VERTICAL,true,true,false);
NumberAxis domainAxis = (NumberAxis) chart.getXYPlot().getDomainAxis();
domainAxis.setAutoRangeIncludesZero(false);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
chartPanel.setVerticalAxisTrace(true);
chartPanel.setHorizontalAxisTrace(true);
setContentPane(chartPanel);
}
public static XYDataset setupData() {
return dataset;
}
public static void addToSet(ArrayList<ArrayList<Double>> coordinates, String classOfData)
{
if(dataset == null)
{
dataset = new XYSeriesCollection();
}
XYSeries series = new XYSeries(classOfData);
for (ArrayList<Double> arrayList : coordinates) {
series.add(arrayList.get(0),arrayList.get(1));
}
dataset.addSeries(series);
}
}