显示TimeSeries JFreeChart上的总时间(以秒为单位)

时间:2014-01-10 06:36:10

标签: java jfreechart

我正在使用TimeSeries jfreechart来显示网络性能。我想显示以秒为单位的总时间,但它只显示从0到59的秒数,然后再次将秒重置为0.我必须显示最近120秒的数据。 / p>

这是代码: 此功能用于创建图表:

private JFreeChart createChart(XYDataset xydataset) {

    result = ChartFactory.createTimeSeriesChart("admin0", "", "MBytes/S", xydataset, true, true, true);
    TextTitle objTitle = new TextTitle("admin0", new Font("Verdana", Font.BOLD, 12));
    result.setTitle(objTitle);

        final XYPlot plot = result.getXYPlot();
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinesVisible(true);
        plot.setBackgroundPaint(Color.WHITE);
        plot.setRangeGridlinePaint(Color.GRAY);
        plot.setDomainGridlinePaint(Color.GRAY);


       DateAxis xaxis = (DateAxis)plot.getDomainAxis();
        xaxis.setAutoRange(true); ////set true to move graph with time.
        xaxis.setFixedAutoRange(120000.0);
        xaxis.setTickUnit(new DateTickUnit(DateTickUnit.SECOND, 15, new SimpleDateFormat("ss")));


        NumberAxis range = (NumberAxis) plot.getRangeAxis();///y-Axis
        range.setRange(0.0, 1.0);
        range.setTickUnit(new NumberTickUnit(0.2));

        XYItemRenderer renderer = plot.getRenderer();
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesPaint(1, Color.GREEN);

        return result;

}

以下是创建数据集的代码:

  private XYDataset createAdmin0DatasetTest() {

     TimeSeriesCollection dataset = new TimeSeriesCollection();

    try
    {

     if(performanceData != null)
     {
         long speed = 0;
         double recieveRate = 0;
         double sendRate = 0;
         long timeinMilli = 0;
         long devider = 4294967296l;
         long snapTime = 0;

         Vector admin0Vec = (Vector)this.performanceData.get("admin0");
            if(admin0Vec != null && admin0Vec.size() > 0)
            {
                Vector innerVec = (Vector)admin0Vec.get(0);             
                recieveRate = Long.parseLong(innerVec.get(2).toString());
                sendRate = Long.parseLong(innerVec.get(1).toString());

                timeinMilli = Long.parseLong(innerVec.get(0).toString());

                }catch(Exception ex)
                {
                    System.out.println("Exception in adding same values");
                }


                for(int i  = 1 ; i < admin0Vec.size() ; i++)
                {
                    innerVec = (Vector)admin0Vec.get(i);                
                    recieveRate = Long.parseLong(innerVec.get(2).toString());
                    sendRate = Long.parseLong(innerVec.get(1).toString());
                    timeinMilli = Long.parseLong(innerVec.get(0).toString());
                    try
                    {
                        this.adminRecieve.addOrUpdate(new Second(new Date(timeinMilli)), recieveRate);
                        this.adminSend.addOrUpdate(new Second(new Date(timeinMilli)), sendRate);

                    }catch(Exception ex)
                    {
                        System.out.println("Exception in adding same values");
                        //ex.printStackTrace();
                    }


                }
                dataset = new TimeSeriesCollection(this.adminRecieve);
                dataset.addSeries(adminSend);

            }
     }
     }catch(Exception ex)
     {
         ex.printStackTrace();
     }

  return dataset;
}

请帮帮我

1 个答案:

答案 0 :(得分:1)

提示:

您正在使用DateAxis作为域轴并将其渲染为秒,因此它肯定只显示数据的秒部分而不计算任何总计。此外,它不必从零开始,只显示120秒的数据。

你想要的不是时间序列,即数字与时间的关系,而是数字与数字的数据序列(经过的秒数)。因此,以这种方式构建它并使用NumberAxis作为域。

注意:上面的内容是为了真正显示总的经过时间,例如:对于秒480和600之间的数据,标签将是例如480,500,520,540,560,580,600(即总数,如标题中所述,因为某些时刻)。如果问题是要有静态标签,例如-120,-100,-80,-60,-40,-20,0,移动数据然后在轴上设置刻度和标签需要以不同方式完成。