如何在图里面画两条曲线啊?
(时间,值)-----(X轴,Y轴)
曲线上的点是从数据库里面取出来的,画一条曲线我做出来了
但是两条就有点问题,只要两条的时间重复了,就画不出来线DefaultCategoryDataset dcds1 = new DefaultCategoryDataset();
dcds.addValue(值,“线1”,时间);
dcds.addValue(值,“线2”,时间);
JFreeChart chart = ChartFactory.createLineChart(title, "指数日期", "指数值", dcds,
               PlotOrientation.VERTICAL, true, true, false);
        configChart(chart);
        JPanel panel = new ChartPanel(chart);
        JOptionPane.showMessageDialog(this, panel);configChart函数:
    public void configChart(JFreeChart chart) {
        CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();        LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
        lineandshaperenderer.setSeriesShapesVisible(0, true);
        lineandshaperenderer.setSeriesShapesVisible(1, true);        lineandshaperenderer.setSeriesLinesVisible(0, true);
        lineandshaperenderer.setSeriesLinesVisible(1, true);        lineandshaperenderer.setDrawOutlines(true);
        lineandshaperenderer.setSeriesStroke(0, new BasicStroke(1F));
        lineandshaperenderer.setSeriesOutlineStroke(0, new BasicStroke(2.0F));
        lineandshaperenderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double( -3D, -3D, 6D, 6D));
    }
是不是哪个参数设错了啊??高手指点一下

解决方案 »

  1.   

    我是在jsp页面里做的
    不过应该能用的上
    注释的部分为画第二条曲线的地方因为我们还没有这个需求,所以只是简单的做了一下,可能还有更好的方案
    <%@ page contentType="text/html;charset=GBK"%>
    <%@ page import="tool.*,table.*,dao.*"%>
    <%@ page import ="
    java.awt.*,
    org.jfree.chart.ChartFactory,
    org.jfree.chart.JFreeChart,
    org.jfree.chart.plot.XYPlot,
    org.jfree.chart.renderer.xy.XYItemRenderer,
    org.jfree.chart.renderer.xy.XYLineAndShapeRenderer,
    org.jfree.data.time.*,
    org.jfree.data.xy.XYDataset,
    org.jfree.chart.axis.ValueAxis,
    org.jfree.ui.*"%>
    <%@ page import="org.jfree.chart.servlet.ServletUtilities"%>
    <%@ page import="java.util.*"%>
    <html>
    <head><title>曲线图输出</title></head>
    <body>
    <%
    ziduan=ziduan+"----"+thm.getHmYhm().trim()+"("+tj.getJName().trim()+tj.getJSim().trim()+")"+"     "+ds.fmatT(start)+"----"+ds.fmatT(end);
    TimeSeries timeseries = new TimeSeries(ziduan,Minute.class);//时间的最小单位为分,线值名是“ziduan”
    //TimeSeries timeseries1 = new TimeSeries("用水量",Minute.class);//时间的最小单位为分,线值名是“ziduan”//从数据库中取值,数据和时间
    Iterator it=list.iterator();
    while(it.hasNext())
    {
    rt=(RpTable)it.next();
    float y0=0;
    String ziDuanZhi="";
    switch(Integer.parseInt(type))
    {
      case 1:
         ziDuanZhi=rt.getSsll();
            break;
    }
    String s1=rt.getCjtime();
    //从yyyyMMddHHmm时间格式的char中取出年月日小时分设为int值
    int x=Integer.parseInt(s1.substring(0,4));
    int y=Integer.parseInt(s1.substring(4,6));
    int z=Integer.parseInt(s1.substring(6,8));
    int a=Integer.parseInt(s1.substring(8,10));
    int b=Integer.parseInt(s1.substring(10,12));
    timeseries.addOrUpdate(new Minute(b,new Hour(a,new Day(z,y,x))),y0);
    //timeseries1.addOrUpdate(new Hour(a,new Day(z,y,x)),y0);
    }//连接曲线
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(timeseries);
    //dataset.addSeries(timeseries1);
    dataset.setDomainIsPointsInTime(true);//设置曲线图
    XYDataset xydataset = (XYDataset) dataset;
    JFreeChart chart = ChartFactory.createTimeSeriesChart(
    "曲线图",
    "时间",
    "值",
    xydataset,
    true,
    true,
    true
    );
    chart.setBackgroundPaint(Color.white);//设置曲线图背景色
    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.getRenderer();
    plot.setBackgroundPaint(Color.white);//设置网格背景颜色
    plot.setDomainGridlinePaint(Color.pink);//设置网格竖线颜色
    plot.setRangeGridlinePaint(Color.pink);//设置网格横线颜色
    plot.setAxisOffset(new RectangleInsets(10D, 10D, 10D, 10D));//设置曲线图与xy轴的距离
    xylineandshaperenderer.setBaseShapesVisible(true);//设置曲线是否显示数据点
    String filename = ServletUtilities.saveChartAsPNG(chart, 980, 450, null, session);
    String graphURL = request.getContextPath() + "/servlets/DisplayChart?filename=" + filename;
    %>
    <img src="<%= graphURL %>" border=0 usemap="#<%= filename %>">
    </body>
    </html>
      

  2.   

    两条我画过,按照jfreechart的函数传参数就可了。