求jfreechart 写的折线图

java源码,一定要有注释!!贴源码百度有限制,要不发我email吧,zph999@163.com一定要有注释!!一定要有注释!!一定要有注释!!一定要有注释!!... java源码,一定要有注释!!
贴源码百度有限制,要不发我email吧, zph999@163.com

一定要有注释!!
一定要有注释!!
一定要有注释!!一定要有注释!!
展开
 我来答
haozhixiang
2008-01-16
知道答主
回答量:50
采纳率:0%
帮助的人:48.1万
展开全部
关注中~
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
以画屏屏8748
2008-01-08 · TA获得超过7191个赞
知道大有可为答主
回答量:2581
采纳率:0%
帮助的人:3292万
展开全部
给你一个例子,参考着改改就行了。jfc_0.9
package org.jfree.chart.demo;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Polygon;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;

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.CategoryPlot;
import org.jfree.chart.plot.DefaultDrawingSupplier;
import org.jfree.chart.plot.DrawingSupplier;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

/**
* A line chart demo showing the use of a custom drawing supplier.
*
*/
public class LineChartDemo5 extends ApplicationFrame {

/**
* Creates a new demo.
*
* @param title the frame title.
*/
public LineChartDemo5(final String title) {
super(title);
final CategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);

}

/**
* Creates a sample dataset.
*
* @return a sample dataset.
*/
private CategoryDataset createDataset() {

// row keys...
final String series1 = "First";
final String series2 = "Second";
final String series3 = "Third";

// column keys...
final String type1 = "Type 1";
final String type2 = "Type 2";
final String type3 = "Type 3";
final String type4 = "Type 4";
final String type5 = "Type 5";
final String type6 = "Type 6";
final String type7 = "Type 7";
final String type8 = "Type 8";

// create the dataset...
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

dataset.addValue(1.0, series1, type1);
dataset.addValue(4.0, series1, type2);
dataset.addValue(3.0, series1, type3);
dataset.addValue(5.0, series1, type4);
dataset.addValue(5.0, series1, type5);
dataset.addValue(7.0, series1, type6);
dataset.addValue(7.0, series1, type7);
dataset.addValue(8.0, series1, type8);

dataset.addValue(5.0, series2, type1);
dataset.addValue(7.0, series2, type2);
dataset.addValue(6.0, series2, type3);
dataset.addValue(8.0, series2, type4);
dataset.addValue(4.0, series2, type5);
dataset.addValue(4.0, series2, type6);
dataset.addValue(2.0, series2, type7);
dataset.addValue(1.0, series2, type8);

dataset.addValue(4.0, series3, type1);
dataset.addValue(3.0, series3, type2);
dataset.addValue(2.0, series3, type3);
dataset.addValue(3.0, series3, type4);
dataset.addValue(6.0, series3, type5);
dataset.addValue(3.0, series3, type6);
dataset.addValue(4.0, series3, type7);
dataset.addValue(3.0, series3, type8);

return dataset;

}

/**
* Creates a sample chart.
*
* @param dataset the dataset.
*
* @return a chart.
*/
private JFreeChart createChart(final CategoryDataset dataset) {

final JFreeChart chart = ChartFactory.createLineChart(
"Line Chart Demo 5", // chart title
"Type", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);

// final StandardLegend legend = (StandardLegend) chart.getLegend();
// legend.setDisplaySeriesShapes(true);

final Shape[] shapes = new Shape[3];
int[] xpoints;
int[] ypoints;

// right-pointing triangle
xpoints = new int[] {-3, 3, -3};
ypoints = new int[] {-3, 0, 3};
shapes[0] = new Polygon(xpoints, ypoints, 3);

// vertical rectangle
shapes[1] = new Rectangle2D.Double(-2, -3, 3, 6);

// left-pointing triangle
xpoints = new int[] {-3, 3, 3};
ypoints = new int[] {0, -3, 3};
shapes[2] = new Polygon(xpoints, ypoints, 3);

final DrawingSupplier supplier = new DefaultDrawingSupplier(
DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE,
DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
shapes
);
final CategoryPlot plot = chart.getCategoryPlot();
plot.setDrawingSupplier(supplier);

chart.setBackgroundPaint(Color.yellow);

// set the stroke for each series...
plot.getRenderer().setSeriesStroke(
0,
new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[] {10.0f, 6.0f}, 0.0f
)
);
plot.getRenderer().setSeriesStroke(
1,
new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[] {6.0f, 6.0f}, 0.0f
)
);
plot.getRenderer().setSeriesStroke(
2,
new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[] {2.0f, 6.0f}, 0.0f
)
);

// customise the renderer...
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
// renderer.setDrawShapes(true);
renderer.setItemLabelsVisible(true);
// renderer.setLabelGenerator(new StandardCategoryLabelGenerator());

// customise the range axis...
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setAutoRangeIncludesZero(false);
rangeAxis.setUpperMargin(0.12);

return chart;

}

// ****************************************************************************
// * JFREECHART DEVELOPER GUIDE *
// * The JFreeChart Developer Guide, written by David Gilbert, is available *
// * to purchase from Object Refinery Limited: *
// * *
// * http://www.object-refinery.com/jfreechart/guide.html *
// * *
// * Sales are used to provide funding for the JFreeChart project - please *
// * support us so that we can continue developing free software. *
// ****************************************************************************

/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(final String[] args) {

final LineChartDemo5 demo = new LineChartDemo5("Line Chart Demo 5");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);

}

}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
capuchin
推荐于2016-12-01 · TA获得超过678个赞
知道小有建树答主
回答量:199
采纳率:0%
帮助的人:111万
展开全部
篇幅限制
我发你邮箱去了
折线图的dataset 两种CatagoryDataset接口(具体实现类是DefaultCategoryDataset),XYDataset 接口
1、CatagoryDataset接口:
A、创建一个数据源(dataset):
private static CategoryDataset createDataset()
{
String series1 = “First”;
String series2 = “Second”;
String series3 = “Third”;
String type1 = “Type 1〃;
String type2 = “Type 2〃;
String type3 = “Type 3〃;
String type4 = “Type 4〃;
String type5 = “Type 5〃;
String type6 = “Type 6〃;
String type7 = “Type 7〃;
String type8 = “Type 8〃;
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
defaultcategorydataset.addValue(1.0D, series1, type1);
defaultcategorydataset.addValue(4D, series1, type2);
defaultcategorydataset.addValue(3D, series1, type3);
defaultcategorydataset.addValue(5D, series1, type4);
defaultcategorydataset.addValue(5D, series1, type5);
defaultcategorydataset.addValue(7D, series1, type6);
defaultcategorydataset.addValue(7D, series1, type7);
defaultcategorydataset.addValue(8D, series1, type8);

defaultcategorydataset.addValue(5D, series2, type1);
defaultcategorydataset.addValue(7D, series2, type2);
defaultcategorydataset.addValue(6D, series2, type3);
defaultcategorydataset.addValue(8D, series2, type4);
defaultcategorydataset.addValue(4D, series2, type5);
defaultcategorydataset.addValue(4D, series2, type6);
defaultcategorydataset.addValue(2D, series2, type7);
defaultcategorydataset.addValue(1.0D, series2, type8);

defaultcategorydataset.addValue(4D, series3, type1);
defaultcategorydataset.addValue(3D, series3, type2);
defaultcategorydataset.addValue(2D, series3, type3);
defaultcategorydataset.addValue(3D, series3, type4);
defaultcategorydataset.addValue(6D, series3, type5);
defaultcategorydataset.addValue(3D, series3, type6);
defaultcategorydataset.addValue(4D, series3, type7);
defaultcategorydataset.addValue(3D, series3, type8);
return defaultcategorydataset;
}
B、由ChartFactory 产生 JFreeChart 对象 (与上面重复的部分就不再注释)
private static JFreeChart createChart(CategoryDataset categorydataset)
{
JFreeChart jfreechart = ChartFactory.createLineChart(”Line Chart Demo 1〃,
“Type”,
“Value”,
categorydataset,
PlotOrientation.VERTICAL,
true,
true,
false);
jfreechart.setBackgroundPaint(Color.white);
CategoryPlot categoryplot = (CategoryPlot)jfreechart.getPlot();
categoryplot.setBackgroundPaint(Color.lightGray);
categoryplot.setRangeGridlinePaint(Color.white);
NumberAxis numberaxis = (NumberAxis)categoryplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
numberaxis.setAutoRangeIncludesZero(true);
//获得renderer 注意这里是下嗍造型到lineandshaperenderer!!
LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer)categoryplot.getRenderer();
lineandshaperenderer.setShapesVisible(true); //series 点(即数据点)可见
lineandshaperenderer.setSeriesStroke(0, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] {
10F, 6F
}, 0.0F)); //定义series为”First”的(即series1)点之间的连线 ,这里是虚线,默认是直线
lineandshaperenderer.setSeriesStroke(1, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] {
6F, 6F
}, 0.0F)); //定义series为”Second”的(即series2)点之间的连线
lineandshaperenderer.setSeriesStroke(2, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] {
2.0F, 6F
}, 0.0F)); //定义series为”Third”的(即series3)点之间的连线
return jfreechart;
}
一些重要的方法:
lineandshaperenderer.setLineVisible(true) //series 点(即数据点)间有连线可见
2、XYDataset 接口:
A、创建一个数据源(dataset):
private static XYDataset createDataset()
{
XYSeries xyseries = new XYSeries(”First”); //先产生XYSeries 对象
xyseries.add(1.0D, 1.0D);
xyseries.add(2D, 4D);
xyseries.add(3D, 3D);
xyseries.add(4D, 5D);
xyseries.add(5D, 5D);
xyseries.add(6D, 7D);
xyseries.add(7D, 7D);
xyseries.add(8D, 8D);

XYSeries xyseries1 = new XYSeries(”Second”);
xyseries1.add(1.0D, 5D);
xyseries1.add(2D, 7D);
xyseries1.add(3D, 6D);
xyseries1.add(4D, 8D);
xyseries1.add(5D, 4D);
xyseries1.add(6D, 4D);
xyseries1.add(7D, 2D);
xyseries1.add(8D, 1.0D);

XYSeries xyseries2 = new XYSeries(”Third”);
xyseries2.add(3D, 4D);
xyseries2.add(4D, 3D);
xyseries2.add(5D, 2D);
xyseries2.add(6D, 3D);
xyseries2.add(7D, 6D);
xyseries2.add(8D, 3D);
xyseries2.add(9D, 4D);
xyseries2.add(10D, 3D);

XYSeriesCollection xyseriescollection = new XYSeriesCollection(); //再用XYSeriesCollection添加入XYSeries 对象
xyseriescollection.addSeries(xyseries);
xyseriescollection.addSeries(xyseries1);
xyseriescollection.addSeries(xyseries2);
return xyseriescollection;
}
B、由ChartFactory 产生 JFreeChart 对象
private static JFreeChart createChart(XYDataset xydataset)
{
JFreeChart jfreechart = ChartFactory.createXYLineChart(”Line Chart Demo 2〃,
“X”,
“Y”,
xydataset,
PlotOrientation.VERTICAL,
true,
true,
false);
jfreechart.setBackgroundPaint(Color.white);
XYPlot xyplot = (XYPlot)jfreechart.getPlot(); //获得 plot:XYPlot!!
xyplot.setBackgroundPaint(Color.lightGray); //设定图表数据显示部分背景色
xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); //设定坐标轴与图表数据显示部分距离
xyplot.setDomainGridlinePaint(Color.white); //网格线颜色
xyplot.setRangeGridlinePaint(Color.white);
//获得 renderer 注意这里是XYLineAndShapeRenderer !!
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)xyplot.getRenderer();
xylineandshaperenderer.setShapesVisible(true); //数据点可见
xylineandshaperenderer.setShapesFilled(true); //数据点被填充即不是空心点
NumberAxis numberaxis = (NumberAxis)xyplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
return jfreechart;
}
一些重要的方法:
XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
xylineandshaperenderer.setSeriesLinesVisible(0, false); //第一个XYSeries数据点间连线不可见
xylineandshaperenderer.setSeriesShapesVisible(1, false); //第二个XYSeries数据点不可见
xyplot.setRenderer(xylineandshaperenderer);

参考资料: http://hi.baidu.com/capchin/blog/item/727fd6c641b5e01f9d163d94.html

本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式