private static JFreeChart createChart() {
   DateAxis dateaxis = new DateAxis("Date");
   dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
   NumberAxis numberaxis = new NumberAxis("Value");
   IntervalXYDataset intervalxydataset = createDataset1();
   XYBarRenderer xybarrenderer = new XYBarRenderer(0.20000000000000001D);
   xybarrenderer.setBaseToolTipGenerator(
       new StandardXYToolTipGenerator(
           "{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
   XYPlot xyplot = new XYPlot(intervalxydataset, dateaxis, numberaxis, xybarrenderer);
   NumberAxis numberaxis1 = new NumberAxis("Value 2");
   xyplot.setRangeAxis(1, numberaxis1);
   XYDataset xydataset = createDataset2A();
   StandardXYItemRenderer standardxyitemrenderer = new StandardXYItemRenderer();
   standardxyitemrenderer.setBaseToolTipGenerator(
       new StandardXYToolTipGenerator(
           "{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
   xyplot.setDataset(1, xydataset);
   xyplot.setRenderer(1, standardxyitemrenderer);
   XYDataset xydataset1 = createDataset2B();
   xyplot.setDataset(2, xydataset1);
   xyplot.setRenderer(2, new StandardXYItemRenderer());
   xyplot.mapDatasetToRangeAxis(2, 1);
   xyplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
   xyplot.setOrientation(PlotOrientation.VERTICAL);
   JFreeChart jfreechart =
       new JFreeChart("Overlaid XYPlot Demo 2", JFreeChart.DEFAULT_TITLE_FONT, xyplot, true);
   ChartUtilities.applyCurrentTheme(jfreechart);
   return jfreechart;
 }
Exemplo n.º 2
0
  protected JFreeChart createChart(
      DSLAMSource source,
      String LID,
      Timeinterval time,
      Properties properties,
      GraphRenderingInput input,
      Map<String, Object> colorScheme,
      Properties outputProperties)
      throws IOException {
    JFreeChart res = null;

    {
      JFreeChart chart = null;

      Timeinterval domainAxisTime = null;

      // Set 'chart':
      {
        String domainAxisTitle = null;

        // Set 'domainAxisTime':
        {
          DateFormat format = (DateFormat) colorScheme.get("date.format");

          domainAxisTitle = "Time (" + time.toString(format) + ")";
        }

        chart =
            ChartFactory.createTimeSeriesChart(
                null, // chart-title
                domainAxisTitle, // domain-axis label
                null, // value-axis label
                null, // dataset
                true, // legends required
                true, // generate tooltips
                false // generate URLs
                );
      }

      XYPlot plot = chart.getXYPlot();

      plot.setOrientation(PlotOrientation.VERTICAL);
      plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
      plot.getRangeAxis().setFixedDimension(15.0);

      // Fix the domain axis:
      {
        fixDateAxisToTimeinterval(plot, time);
        domainAxisTime = time;
      }

      // Set the y-axis:
      {
        String axisTitle = "Count (/900s)";

        ValueAxis a = new LogarithmicAxis(axisTitle);
        a.setLowerBound(0);
        a.setUpperBound(1000); // TODO: '1000' is '900' rounded up to nearest power of 10!
        // TODO: Get unit from data-model!
        // TODO: Get upper bound from data-model!

        plot.setRangeAxis(a);
      }

      String title = getTitle();
      setDefaults(chart, colorScheme);
      setTitle(chart, LID, colorScheme, title, source, time);

      String filter = ""; // an empty string implies the default filter!

      // Set 'filter':
      {
        if (input != null) {
          Properties p = input.getProperties();
          if (p != null) {
            String v = p.getProperty("data.filter");
            if (v != null) {
              filter = v;
            }
          }
        }
      }

      addData(chart, source, time, filter, properties, colorScheme, outputProperties);

      if (outputProperties != null) {
        if (domainAxisTime != null) {
          outputProperties.setProperty("axis.domain.time", time.toString());
        }
      }

      res = chart;
    }

    return res;
  }