Exemplo n.º 1
0
    public MyDemoPanel() {
      super(new BorderLayout());
      lastValue = new double[3];
      CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new DateAxis("Time"));
      datasets = new TimeSeriesCollection[3];
      for (int i = 0; i < 3; i++) {
        lastValue[i] = 100D;
        TimeSeries timeseries = new TimeSeries("Random " + i);
        datasets[i] = new TimeSeriesCollection(timeseries);
        NumberAxis numberaxis = new NumberAxis("Y" + i);
        numberaxis.setAutoRangeIncludesZero(false);
        XYPlot xyplot = new XYPlot(datasets[i], null, numberaxis, new StandardXYItemRenderer());
        xyplot.setBackgroundPaint(Color.lightGray);
        xyplot.setDomainGridlinePaint(Color.white);
        xyplot.setRangeGridlinePaint(Color.white);
        combineddomainxyplot.add(xyplot);
      }

      JFreeChart jfreechart = new JFreeChart("Dynamic Data Demo 3", combineddomainxyplot);
      addChart(jfreechart);
      LegendTitle legendtitle = (LegendTitle) jfreechart.getSubtitle(0);
      legendtitle.setPosition(RectangleEdge.RIGHT);
      legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D));
      jfreechart.setBorderPaint(Color.black);
      jfreechart.setBorderVisible(true);
      ValueAxis valueaxis = combineddomainxyplot.getDomainAxis();
      valueaxis.setAutoRange(true);
      valueaxis.setFixedAutoRange(20000D);
      ChartUtilities.applyCurrentTheme(jfreechart);
      ChartPanel chartpanel = new ChartPanel(jfreechart);
      add(chartpanel);
      JPanel jpanel = new JPanel(new FlowLayout());
      for (int j = 0; j < 3; j++) {
        JButton jbutton1 = new JButton("Series " + j);
        jbutton1.setActionCommand("ADD_DATA_" + j);
        jbutton1.addActionListener(this);
        jpanel.add(jbutton1);
      }

      JButton jbutton = new JButton("ALL");
      jbutton.setActionCommand("ADD_ALL");
      jbutton.addActionListener(this);
      jpanel.add(jbutton);
      add(jpanel, "South");
      chartpanel.setPreferredSize(new Dimension(500, 470));
      chartpanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    }
Exemplo n.º 2
0
 private static JFreeChart createChart(XYDataset xydataset) {
   JFreeChart jfreechart =
       ChartFactory.createTimeSeriesChart(
           "Legal & General Unit Trust Prices",
           "Date",
           "Price Per Unit",
           xydataset,
           true,
           true,
           false);
   XYPlot xyplot = (XYPlot) jfreechart.getPlot();
   xyplot.setDomainCrosshairVisible(true);
   xyplot.setRangeCrosshairVisible(true);
   org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
   if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
     XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
     xylineandshaperenderer.setBaseShapesVisible(true);
     xylineandshaperenderer.setBaseShapesFilled(true);
     xylineandshaperenderer.setBaseItemLabelsVisible(true);
   }
   PeriodAxis periodaxis = new PeriodAxis("Date");
   periodaxis.setTimeZone(TimeZone.getTimeZone("Pacific/Auckland"));
   periodaxis.setAutoRangeTimePeriodClass(org.jfree.data.time.Day.class);
   PeriodAxisLabelInfo aperiodaxislabelinfo[] = new PeriodAxisLabelInfo[3];
   aperiodaxislabelinfo[0] =
       new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("d"));
   aperiodaxislabelinfo[1] =
       new PeriodAxisLabelInfo(
           org.jfree.data.time.Month.class,
           new SimpleDateFormat("MMM"),
           new RectangleInsets(2D, 2D, 2D, 2D),
           new Font("SansSerif", 1, 10),
           Color.blue,
           false,
           new BasicStroke(0.0F),
           Color.lightGray);
   aperiodaxislabelinfo[2] =
       new PeriodAxisLabelInfo(org.jfree.data.time.Year.class, new SimpleDateFormat("yyyy"));
   periodaxis.setLabelInfo(aperiodaxislabelinfo);
   xyplot.setDomainAxis(periodaxis);
   ChartUtilities.applyCurrentTheme(jfreechart);
   return jfreechart;
 }