我指的是:
但我无法看到我的 x,y 数据点的形状:
public void plotHysteresis()
{
s1= new double[6];
s2= new double[6];
s3= new double[6];
s4= new double[6];
int i=0;
for(i=0;i<6;i++)
{
s1[i]=hyst[i];
System.out.println("s1[" +i +"] : " +s1[i] +"\n");
}
for(i=0;i<6;i++)
{
s2[i]=hyst[10-i];
System.out.println("s2[" +i +"] : " +s2[i] +"\n");
}
for(i=0;i<6;i++)
{
s3[i]=hyst[11+i];
System.out.println("s3[" +i +"] : " +s3[i] +"\n");
}
for(i=0;i<6;i++)
{
s4[i]=hyst[21-i];
System.out.println("s4[" +i +"] : " +s4[i] +"\n");
}
// DefaultCategoryDataset dataset = new DefaultCategoryDataset();
XYSeries series3 = new XYSeries("III");
int x=-25;
System.out.println(x +"***\n");
for(i=5;i>=0;i--)
{
series3.add(x,s3[i]);
x=x+5;
}
System.out.println(x +"***\n");
XYSeries series4 = new XYSeries("IV");
for(i=0;i<6;i++)
{
x=x-5;
series4.add(x,s4[i] );
}
System.out.println(x +"###\n");
XYSeries series1 = new XYSeries("I");
x=0;
for(i=0;i<6;i++)
{
series1.add(x,s1[i] );
x=x+5;
}
// x=x-5;
System.out.println(x +"***\n");
XYSeries series2 = new XYSeries("II");
for(i=5;i>=0;i--)
{
x=x-5;
series2.add(x,s2[i] );
}
System.out.println(x +"***\n");
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series3);
dataset.addSeries(series4);
dataset.addSeries(series1);
dataset.addSeries(series2);
JFreeChart chart = ChartFactory.createXYLineChart(
"Hysteresis Plot", // chart title
"Pounds(lb)", // domain axis label
"Movement(inch)", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
false, // include legend
true, // tooltips
false // urls
);
chart.setBackgroundPaint(Color.white);
//chart.setBackgroundPaint(new Color(249, 231, 236));
/*CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setRangeGridlinePaint(Color.white);
plot.getRenderer().setSeriesPaint(0, Color.BLUE);
plot.getRenderer().setSeriesPaint(1, Color.BLUE);
plot.getRenderer().setSeriesPaint(2, Color.BLUE);
plot.getRenderer().setSeriesPaint(3, Color.BLUE);*/
Shape cross = ShapeUtilities.createRegularCross(4, 3);
XYPlot plot = (XYPlot) chart.getPlot();
XYItemRenderer renderer = plot.getRenderer();
renderer.setSeriesPaint(0, Color.RED);
renderer.setSeriesPaint(1, Color.RED);
renderer.setSeriesPaint(2, Color.RED);
renderer.setSeriesPaint(3, Color.RED);
renderer.setSeriesShape(0, cross);
renderer.setSeriesShape(1, cross);
renderer.setSeriesShape(2, cross);
renderer.setSeriesShape(3, cross);
renderer.setSeriesVisible(0,true);
renderer.setSeriesVisible(1,true);
renderer.setSeriesVisible(2,true);
renderer.setSeriesVisible(3,true);
plot.setDomainCrosshairVisible(true);//Sets Y axis visible blue
plot.setRangeCrosshairVisible(true);//Sets X axis visible blue
/*LineAndShapeRenderer rend
= (LineAndShapeRenderer) plot.getRenderer();
rend.setShapesVisible(true);*/
//renderer.setDrawOutlines(true);
//renderer.setUseFillPaint(true);
//renderer.setFillPaint(Color.white);
ChartPanel frame = new ChartPanel(chart);
frame.setVisible(true);
frame.setSize(plotPanel.getWidth(),plotPanel.getHeight());
plotPanel.add(frame);
plotPanel.repaint();
}
上面的代码给了我输出:
早些时候,我能够看到带有 CategoryPlot 和 LineChart 的形状,如代码的注释部分所示,但它不适用于 XYLineChart。
请帮忙谢谢
得到了解决方案: How to get diamond shape for points in JFreechart Can I change the color of plot.setDomainCrosshairVisible(true);//设置Y轴可见蓝色 plot.setRangeCrosshairVisible(true);//设置X轴可见蓝色想要使它变黑而不是显示为蓝色。