日期:2014-05-17 浏览次数:20816 次
package lianxi;
import java.awt.BasicStroke;
import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
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.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYSplineRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class DockApplet extends ApplicationFrame {
private static final long serialVersionUID = 1L;
public DockApplet(String s) {
super(s);
setContentPane(createDemoLine());
}
public static void main(String[] args) {
DockApplet fjc = new DockApplet("曲线图");
fjc.pack();
RefineryUtilities.centerFrameOnScreen(fjc);
fjc.setVisible(true);
}
// 生成显示图表的面板
public static JPanel createDemoLine() {
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
}
// 生成图表主对象JFreeChart
public static JFreeChart createChart(XYDataset linedataset) {
XYSplineRenderer splinerenderer = new XYSplineRenderer();
// splinerenderer.setBaseShapesVisible(false); //绘制的线条上不显示图例,如果显示的话,会使图片变得很丑陋
// splinerenderer.setSeriesPaint(0, Color.yellow); //设置0号数据的颜色。这是手工设置线条颜色的方法
// splinerenderer.setPrecision(5); //设置精度,大概意思是在源数据两个点之间插入5个点以拟合出一条平滑曲线
splinerenderer.setSeriesStroke(0, new BasicStroke(4.0F, 1, 1, 1.0F));
// splinerenderer.setSeriesStroke(1, new BasicStroke(2.0F, 1, 1, 1.0F,
// new float[] { 10F, 6F }, 0.0F));
// splinerenderer.setSeriesStroke(2, new BasicStroke(2.0F, 1, 1, 1.0F,
// new float[] { 10F, 6F }, 0.0F));
//设置线
//create plot
NumberAxis xAxis = new NumberAxis("切变率(1/s)");
xAxis.setAutoRangeIncludesZero(false);
NumberAxis yAxis = new NumberAxis("粘度(mPa.s)");
yAxis.setAutoRangeIncludesZero(false);
XYPlot plot = new XYPlot(createDataset(), xAxis, yAxis, splinerenderer);
// x轴 // 分类轴网格是否可见
plot.setDomainGridlinesVisible(true);
// y轴 //数据轴网格是否可见
plot.setRangeGridlinesVisible(true);