/*     */ private static JFreeChart createChart(XYDataset dataset) /*     */ {
   /*  93 */ JFreeChart chart =
       ChartFactory.createTimeSeriesChart(
           "Legal & General Unit Trust Prices",
           "Date",
           "Price Per Unit",
           dataset,
           true,
           true,
           false);
   /*     */
   /* 103 */ chart.setBackgroundPaint(Color.white);
   /*     */
   /* 105 */ XYPlot plot = (XYPlot) chart.getPlot();
   /* 106 */ plot.setBackgroundPaint(Color.lightGray);
   /* 107 */ plot.setDomainGridlinePaint(Color.white);
   /* 108 */ plot.setRangeGridlinePaint(Color.white);
   /* 109 */ plot.setAxisOffset(new RectangleInsets(5.0D, 5.0D, 5.0D, 5.0D));
   /* 110 */ plot.setDomainCrosshairVisible(true);
   /* 111 */ plot.setRangeCrosshairVisible(true);
   /*     */
   /* 113 */ XYItemRenderer r = plot.getRenderer();
   /* 114 */ if ((r instanceof XYLineAndShapeRenderer)) {
     /* 115 */ XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
     /* 116 */ renderer.setBaseShapesVisible(true);
     /* 117 */ renderer.setBaseShapesFilled(true);
     /* 118 */ renderer.setDrawSeriesLineAsPath(true);
     /*     */ }
   /*     */
   /* 121 */ DateAxis axis = (DateAxis) plot.getDomainAxis();
   /* 122 */ axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
   /*     */
   /* 124 */ return chart;
   /*     */ }
Example #2
0
  /**
   * Creates a chart.
   *
   * @param dataset a dataset.
   * @return A chart.
   */
  private static JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart =
        ChartFactory.createTimeSeriesChart(
            "Rapporto Entrata/uscita nel tempo", // title
            "Date", // x-axis label
            "Quantita", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
            );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
      XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
      renderer.setBaseShapesVisible(true);
      renderer.setBaseShapesFilled(true);
      renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("dd-MMM-yyyy"));

    return chart;
  }
  private static JFreeChart createChart(
      XYDataset dataset,
      String applicationTitle,
      String chartTitle,
      String xlabel,
      String ylabel,
      String name) {
    JFreeChart chart =
        ChartFactory.createScatterPlot(
            chartTitle, xlabel, ylabel, dataset, PlotOrientation.VERTICAL, true, false, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesOutlinePaint(0, Color.black);
    renderer.setUseOutlinePaint(true);
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setTickMarkInsideLength(2.0f);
    domainAxis.setTickMarkOutsideLength(0.0f);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setTickMarkInsideLength(2.0f);
    rangeAxis.setTickMarkOutsideLength(0.0f);

    return chart;
  }
 private static JFreeChart createChart(XYDataset xydataset) {
   JFreeChart jfreechart =
       ChartFactory.createTimeSeriesChart(
           "Exercise Chart", "Elapsed Time", "Beats Per Minute", xydataset, true, true, false);
   jfreechart.setBackgroundPaint(Color.white);
   XYPlot xyplot = (XYPlot) jfreechart.getPlot();
   xyplot.setBackgroundPaint(Color.lightGray);
   xyplot.setDomainGridlinePaint(Color.white);
   xyplot.setRangeGridlinePaint(Color.white);
   xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
   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);
   }
   DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
   Minute minute = new Minute(0, 9, 1, 10, 2006);
   RelativeDateFormat relativedateformat = new RelativeDateFormat(minute.getFirstMillisecond());
   relativedateformat.setSecondFormatter(new DecimalFormat("00"));
   dateaxis.setDateFormatOverride(relativedateformat);
   return jfreechart;
 }
  private void init() {
    timeSeriesList = new LinkedList<TimeSeries>();
    m_average = new TimeSeries(AVERANGE, Millisecond.class);
    m_tps = new TimeSeries(TPS, Millisecond.class);
    m_deviation = new TimeSeries(DEVIATION, Millisecond.class);
    stateMap.put(AVERANGE, m_average);
    stateMap.put(DEVIATION, m_deviation);
    stateMap.put(TPS, m_tps);
    timeSeriesList.add(m_average);
    timeSeriesList.add(m_tps);
    timeSeriesList.add(m_deviation);
    timeseriescollection = new TimeSeriesCollection();
    for (Iterator<TimeSeries> iterator = timeSeriesList.iterator(); iterator.hasNext(); ) {
      timeseriescollection.addSeries(iterator.next());
    }
    jfc =
        ChartFactory.createTimeSeriesChart(
            "Title", "unit", "yaxisName", timeseriescollection, true, true, false);
    // jfc.setTitle(new TextTitle("图表", new Font("黑体", Font.BOLD, 20)));
    // 取得统计图表
    XYPlot xyplot = jfc.getXYPlot();

    xylinerenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylinerenderer.setSeriesPaint(0, Color.BLUE);
    xylinerenderer.setSeriesPaint(1, Color.GREEN);
    xylinerenderer.setSeriesPaint(2, Color.RED);

    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setAutoRange(true);
    valueaxis.setFixedAutoRange(30000D);
    valueaxis = xyplot.getRangeAxis();
    chartPanel = new ChartPanel(jfc);
    chartPanel.setPreferredSize(new Dimension(600, 450));
  }
Example #6
0
  private static JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart =
        ChartFactory.createXYLineChart(
            "Ratings by Age", // Title
            "Age", // X label
            "Average Rating", // Y label
            dataset, // data
            PlotOrientation.VERTICAL, // Orientation
            false, // legend
            false, // tooltips
            false); // urls
    chart.setBorderPaint(Color.white);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;
  }
  public void displayWithOtherSignals(
      ArrayList<GeneralSignal> otherSignals, String title, boolean shapeVisible) {
    JFreeChart chart;

    XYSeriesCollection xyDataSet = new XYSeriesCollection(this.data);
    for (int i = 0; i < otherSignals.size(); i++) {
      xyDataSet.addSeries(otherSignals.get(i).getData());
    }

    chart =
        ChartFactory.createXYLineChart(
            title, // Title
            "Abscissa", // X axis label
            "Ordinate", // Y axis label
            xyDataSet, // dataset
            PlotOrientation.VERTICAL, // orientation
            true, // legends
            true, // tool tips
            true); // urls

    if (shapeVisible) {
      XYPlot plot = (XYPlot) chart.getPlot();
      XYItemRenderer r = plot.getRenderer();
      if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setSeriesShapesVisible(0, true);
        renderer.setSeriesShapesFilled(0, true);
      }
    }

    ChartFrame frame = new ChartFrame("Frame Title", chart);
    frame.setVisible(true);
    frame.setSize(512, 512);
  }
  private JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart =
        ChartFactory.createTimeSeriesChart(
            "Updating time series chart", "Date", "Value", dataset, true, true, false);

    chart.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
      XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
      renderer.setBaseShapesVisible(true);
      renderer.setBaseShapesFilled(true);
      renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy-dd HH:mm:ss"));

    return chart;
  }
  /**
   * This method renders a line chart of income and expense entries over 1-month intervals
   *
   * @param dataset
   * @return financesLineChart_PNL
   */
  private ChartPanel renderLineChart(XYDataset dataset) {

    // Create JFreeChart with dataSet
    JFreeChart lineChart =
        ChartFactory.createTimeSeriesChart("", "", "Amount", dataset, true, true, false);

    // Change the x-axis (time interval) format
    XYPlot plot = (XYPlot) lineChart.getPlot();
    DateAxis dateAxis = (DateAxis) plot.getDomainAxis();
    dateAxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    // Change the chart's visual properties
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
      XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
      renderer.setBaseShapesVisible(true);
      renderer.setBaseShapesFilled(true);
      renderer.setDrawSeriesLineAsPath(true);
    }

    // Create and format the chart panel
    ChartPanel financesLineChart_PNL =
        new ChartPanel(lineChart, 600, 250, 200, 100, 800, 300, true, true, true, true, true, true);
    financesLineChart_PNL.setSize(800, 300);

    return financesLineChart_PNL;
  }
  private JFreeChart createChart(final GraphBuilder builder) {
    final JFreeChart chart =
        ChartFactory.createXYLineChart(
            builder.graphTitle(),
            builder.xAxisLabel(),
            builder.yAxisLabel(),
            builder.dataset(),
            PlotOrientation.VERTICAL,
            true, // include legend
            true, // tooltips
            false // urls
            );

    chart.setBackgroundPaint(Color.white);
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final ValueAxis rangeAxis = plot.getRangeAxis();
    // rangeAxis.setRange(0,20);

    final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseItemLabelsVisible(true);

    if (builder.yRange0To1()) {
      chart.getXYPlot().getRangeAxis().setRange(0.0, 1.0);
    }

    return chart;
  }
Example #11
0
 private XYItemRenderer getLineRenderer() throws KeyedException {
   XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
   lineRenderer.setDrawSeriesLineAsPath(true);
   lineRenderer.setSeriesStroke(
       0, new BasicStroke(getStrokeWidth(), BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND));
   lineRenderer.setBaseShapesVisible(false);
   return lineRenderer;
 }
 /**
  * Returns a clone of the renderer.
  *
  * @return A clone.
  * @throws CloneNotSupportedException if the clone cannot be created.
  */
 public Object clone() throws CloneNotSupportedException {
   XYLineAndShapeRenderer clone = (XYLineAndShapeRenderer) super.clone();
   clone.seriesLinesVisible = (BooleanList) this.seriesLinesVisible.clone();
   if (this.legendLine != null) {
     clone.legendLine = ShapeUtilities.clone(this.legendLine);
   }
   clone.seriesShapesVisible = (BooleanList) this.seriesShapesVisible.clone();
   clone.seriesShapesFilled = (BooleanList) this.seriesShapesFilled.clone();
   return clone;
 }
 protected JFreeChart createScatterChart() throws JRException {
   JFreeChart jfreeChart = super.createScatterChart();
   XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
   xyPlot.setDomainGridlinesVisible(false);
   XYLineAndShapeRenderer plotRenderer =
       (XYLineAndShapeRenderer) ((XYPlot) jfreeChart.getPlot()).getRenderer();
   plotRenderer.setBaseShapesFilled(false);
   plotRenderer.setBaseStroke(new BasicStroke(1f));
   return jfreeChart;
 }
  /**
   * Displays a signal (using the JFreeChart package).
   *
   * @param useChart if set to true, the signal is displaied as a bar chart (this is used for
   *     histograms).
   */
  public void display(boolean useChart) {

    JFreeChart chart;
    int nbSamples = getNbSamples();

    if (useChart) {
      String[] categories = new String[nbSamples];
      for (int i = 0; i < nbSamples; i++) {
        categories[i] = data.getX(i).toString();
      }
      String[] categoryNames = {"Histogram"};
      double[][] categoryData = new double[1][nbSamples];
      for (int i = 0; i < nbSamples; i++) {
        categoryData[0][i] = data.getY(i).doubleValue();
      }

      CategoryDataset categoryDataset =
          DatasetUtilities.createCategoryDataset(categoryNames, categories, categoryData);

      chart =
          ChartFactory.createBarChart(
              "Histogram", // Title
              "Data Value", // X axis label
              "Number of Elements", // Y axis label
              categoryDataset, // dataset
              PlotOrientation.VERTICAL, // orientation
              true, // legends
              true, // tool tips
              true);
    } else {
      XYDataset xyDataSet = new XYSeriesCollection(this.data);
      chart =
          ChartFactory.createXYLineChart(
              "Example Dataset", // Title
              "Abscissa", // X axis label
              "Ordinate", // Y axis label
              xyDataSet, // dataset
              PlotOrientation.VERTICAL, // orientation
              true, // legends
              true, // tool tips
              true); // urls

      XYPlot plot = (XYPlot) chart.getPlot();
      XYItemRenderer r = plot.getRenderer();
      if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setSeriesShapesVisible(0, true);
        renderer.setSeriesShapesFilled(0, true);
      }
    }

    ChartFrame frame = new ChartFrame("Frame Title", chart);
    frame.setVisible(true);
    frame.setSize(512, 512);
  }
  /**
   * @param forecast
   * @param settings (next days)
   * @return
   */
  public JFreeChart createBarChart(
      final LiquidityForecast forecast, final LiquidityForecastSettings settings) {
    Validate.isTrue(settings.getNextDays() > 0 && settings.getNextDays() < 500);
    final LiquidityForecastCashFlow cashFlow =
        new LiquidityForecastCashFlow(forecast, settings.getNextDays());
    final TimeSeries accumulatedSeriesExpected =
        new TimeSeries(I18n.getString("plugins.liquidityplanning.forecast.expected"));
    final TimeSeries creditSeries =
        new TimeSeries(I18n.getString("plugins.liquidityplanning.common.credit"));
    final TimeSeries debitSeries =
        new TimeSeries(I18n.getString("plugins.liquidityplanning.common.debit"));
    double accumulatedExpected = settings.getStartAmount().doubleValue();

    final DayHolder dh = new DayHolder();
    final Date lower = dh.getDate();
    for (int i = 0; i < settings.getNextDays(); i++) {
      final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear());
      if (i > 0) {
        accumulatedExpected +=
            cashFlow.getDebitsExpected()[i - 1].doubleValue()
                + cashFlow.getCreditsExpected()[i - 1].doubleValue();
      }
      accumulatedSeriesExpected.add(day, accumulatedExpected);
      creditSeries.add(day, cashFlow.getCreditsExpected()[i].doubleValue());
      debitSeries.add(day, cashFlow.getDebitsExpected()[i].doubleValue());
      dh.add(Calendar.DATE, 1);
    }
    dh.add(Calendar.DATE, -1);
    final XYChartBuilder cb =
        new XYChartBuilder(
            ChartFactory.createXYBarChart(
                null, null, false, null, null, PlotOrientation.VERTICAL, false, false, false));
    int counter = 0;

    final TimeSeriesCollection xyDataSeries = new TimeSeriesCollection();
    xyDataSeries.addSeries(accumulatedSeriesExpected);
    final XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, true);
    lineRenderer.setSeriesPaint(0, cb.getRedMarker());
    lineRenderer.setSeriesVisibleInLegend(0, true);
    cb.setRenderer(counter, lineRenderer)
        .setDataset(counter++, xyDataSeries)
        .setStrongStyle(lineRenderer, false, accumulatedSeriesExpected);

    final TimeSeriesCollection cashflowSet = new TimeSeriesCollection();
    cashflowSet.addSeries(debitSeries);
    cashflowSet.addSeries(creditSeries);
    final XYBarRenderer barRenderer = new XYBarRenderer(.2);
    barRenderer.setSeriesPaint(0, cb.getGreenFill());
    barRenderer.setSeriesPaint(1, cb.getRedFill());
    barRenderer.setShadowVisible(false);
    cb.setRenderer(counter, barRenderer).setDataset(counter++, cashflowSet);

    cb.setDateXAxis(true).setDateXAxisRange(lower, dh.getDate()).setYAxis(true, null);
    return cb.getChart();
  }
Example #16
0
  @Override
  public JComponent getVisualisation(DataBean data) throws Exception {

    this.data = data;

    refreshAxisBoxes(data);

    List<Variable> vars = getFrame().getVariables();
    if (vars == null || vars.size() < 2) {
      if (xBox.getItemCount() >= 1) {
        xBox.setSelectedIndex(0);
      }
      if (yBox.getItemCount() >= 2) {
        yBox.setSelectedIndex(1);
      } else {
        yBox.setSelectedIndex(0);
      }
    } else {
      xBox.setSelectedItem(vars.get(0));
      yBox.setSelectedItem(vars.get(1));
    }

    xVar = (Variable) xBox.getSelectedItem();
    yVar = (Variable) yBox.getSelectedItem();

    PlotDescription description =
        new PlotDescription(data.getName(), xVar.getName(), yVar.getName());

    NumberAxis domainAxis = new NumberAxis(description.xTitle);
    domainAxis.setAutoRangeIncludesZero(false);
    NumberAxis rangeAxis = new NumberAxis(description.yTitle);
    rangeAxis.setAutoRangeIncludesZero(false);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLinesVisible(false);
    renderer.setShapesVisible(true);
    renderer.setShape(new Ellipse2D.Float(-2, -2, 4, 4));
    renderer.setSeriesPaint(1, Color.black);

    plot = new XYPlot(new XYSeriesCollection(), domainAxis, rangeAxis, renderer);

    this.updateSelectionsFromApplication(false); // Calls also updateXYSerieses();

    JFreeChart chart = new JFreeChart(description.plotTitle, plot);

    application.addClientEventListener(this);

    selectableChartPanel = new SelectableChartPanel(chart, this);
    return selectableChartPanel;
  }
  ChartPanelShowStatistics(
      String title,
      String timeAxisLabel,
      String valueAxisLabel,
      XYDataset dataset /*, boolean legend, boolean tooltips, boolean urls*/) {
    this();
    // chart = ChartFactory.createTimeSeriesChart(title, timeAxisLabel, valueAxisLabel, dataset);
    chart = ChartFactory.createScatterPlot(title, timeAxisLabel, valueAxisLabel, dataset);
    ChartPanel p = new ChartPanel(chart);
    add(p, BorderLayout.CENTER);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();

    renderer.setBaseShapesVisible(false);
    //		renderer.setBaseShape(itemShape);	// 好像不管用,必须用setSeriesShape
    renderer.setBaseLinesVisible(true);
    //		renderer.setBasePaint(new Color(0));	// 好像不管用,必须用setSeriesPaint

    itemShape = ShapeUtilities.createDiamond((float) 3);
    renderer.setSeriesShape(0, itemShape);
    renderer.setSeriesPaint(0, new Color(255, 0, 0));

    renderer.setSeriesShape(1, itemShape);
    renderer.setSeriesPaint(1, new Color(0, 255, 0));

    renderer.setBaseToolTipGenerator(
        new StandardXYToolTipGenerator(
            "{0}:({1} , {2})",
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), new DecimalFormat("#.00")));
  }
  public void setMin(float min) {
    for (int i = 0; i < minData.length; i++) {
      minData[i] = min;
    }

    XYSeriesCollection minCol = PlotingToolkit.getCollection(xData, minData, "Min");

    XYLineAndShapeRenderer minRender = new XYLineAndShapeRenderer(true, false);
    minRender.setSeriesPaint(0, Color.RED);

    previewPlot.getXYPlot().setRenderer(1, minRender);
    dataPlot.getXYPlot().setRenderer(1, minRender);

    dataPlot.getXYPlot().setDataset(1, minCol);
    previewPlot.getXYPlot().setDataset(1, minCol);
  }
  public void setMax(float max) {
    for (int i = 0; i < maxData.length; i++) {
      maxData[i] = max;
    }

    XYSeriesCollection maxCol = PlotingToolkit.getCollection(xData, maxData, "Max");

    XYLineAndShapeRenderer maxRender = new XYLineAndShapeRenderer(true, false);
    maxRender.setSeriesPaint(0, Color.MAGENTA);

    previewPlot.getXYPlot().setRenderer(2, maxRender);
    dataPlot.getXYPlot().setRenderer(2, maxRender);

    dataPlot.getXYPlot().setDataset(2, maxCol);
    previewPlot.getXYPlot().setDataset(2, maxCol);
  }
  /**
   * Creates a chart.
   *
   * @param dataset the data for the chart.
   * @return a chart.
   */
  private JFreeChart createChart(XYDataset dataset) {
    // create the chart...

    JFreeChart chart =
        ChartFactory.createXYLineChart(
            region + ", flows " + flowlist + " " + baselist, // chart
            // title
            "timestamp",
            getYaxis(), // y axis label
            dataset, // data
            PlotOrientation.VERTICAL,
            true, // include legend
            true, // tooltips
            false // urls
            );

    if (subtitle != null) {
      final TextTitle s = new TextTitle(subtitle);
      s.setFont(new Font("SansSerif", Font.PLAIN, 12));
      s.setPosition(RectangleEdge.TOP);
      //        subtitle.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.05));
      //  s.setVerticalAlignment(VerticalAlignment.TOP);
      chart.addSubtitle(s);
    }
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    // chart.setBackgroundPaint(Color.white);
    chart.setBackgroundImageAlpha(1.0f);
    // chart.addSubtitle(new TextTitle(file.getName()));
    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();

    plot.setBackgroundPaint(Color.black);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setShapesVisible(false);
    renderer.setShapesFilled(false);

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    ValueAxis va = plot.getDomainAxis();
    va.setAutoRangeMinimumSize(1000);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
  }
  private void updateColor() {
    int len = timeseriescollection.getSeriesCount();
    if (len != 0) {
      for (int i = 0; i < len; i++) {
        TimeSeries t = timeseriescollection.getSeries(i);
        if (t.getKey().equals(AVERANGE)) {
          xylinerenderer.setSeriesPaint(i, Color.BLUE);
        } else if (t.getKey().equals(TPS)) {
          xylinerenderer.setSeriesPaint(i, Color.GREEN);
        } else if (t.getKey().equals(DEVIATION)) {
          xylinerenderer.setSeriesPaint(i, Color.RED);
        } else {

        }
      }
    }
  }
Example #22
0
 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();
   xyplot.setBackgroundPaint(Color.lightGray);
   xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
   xyplot.setDomainGridlinePaint(Color.white);
   xyplot.setRangeGridlinePaint(Color.white);
   XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
   xylineandshaperenderer.setBaseShapesVisible(true);
   xylineandshaperenderer.setBaseShapesFilled(true);
   NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
   numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   return jfreechart;
 }
Example #23
0
  public static void generateXYScatterPlot(
      String fileName, double[] x, double[] y, String title, String xLabel, String yLabel) {

    if (x.length != y.length) {
      DebugLib.stopSystemAndReportInconsistency("dimensions of arrays do not match");
    }

    final XYSeries series1 = new XYSeries(title);

    for (int i = 0; i < x.length; i++) {
      series1.add(x[i], y[i]);
    }

    final XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series1);

    final JFreeChart chart =
        ChartFactory.createXYLineChart(
            title, xLabel, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    int width = 500;
    int height = 300;

    try {
      ChartUtilities.saveChartAsPNG(new File(fileName), chart, width, height);
    } catch (IOException e) {

    }
  }
Example #24
0
  private JFreeChart createChart(XYDataset dataset, String title) {

    // create the chart...
    final JFreeChart chart =
        ChartFactory.createXYLineChart(
            title, // chart title
            "x", // domain axis label
            "y", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
            );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);
    //    legend.setShapeScaleX(1.5);
    //  legend.setShapeScaleY(1.5);
    // legend.setDisplaySeriesLines(true);

    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(false);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(1, true);
    renderer.setSeriesShapesVisible(1, false);
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, false);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
  }
Example #25
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;
 }
  /**
   * create the chart for the original time series
   *
   * @param tsData the data to plot.
   * @return a JFreeChart object of the chart
   */
  private void paintTheChart(double[] tsData) {

    // making the data
    //
    XYSeries dataset = new XYSeries("Series");
    for (int i = 0; i < tsData.length; i++) {
      dataset.add(i, (float) tsData[i]);
    }
    chartXYSeriesCollection = new XYSeriesCollection(dataset);

    // set the renderer
    //
    XYLineAndShapeRenderer xyRenderer = new XYLineAndShapeRenderer(true, false);
    xyRenderer.setSeriesPaint(0, new Color(0, 0, 0));
    xyRenderer.setBaseStroke(new BasicStroke(3));

    // X - the time axis
    //
    NumberAxis timeAxis = new NumberAxis("Time. (zoom: select with mouse; panning: Ctrl+mouse)");

    // Y axis
    //
    NumberAxis valueAxis = new NumberAxis("Values");
    valueAxis.setAutoRangeIncludesZero(false);

    // put these into collection of dots
    //
    this.timeseriesPlot = new XYPlot(chartXYSeriesCollection, timeAxis, valueAxis, xyRenderer);

    // enabling panning
    //
    this.timeseriesPlot.setDomainPannable(true);
    this.timeseriesPlot.setRangePannable(true);

    // finally, create the chart
    this.chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, timeseriesPlot, false);

    // set the progress listener to react to mouse clicks in the chart
    this.chart.addProgressListener(this);
  }
  private JFreeChart createChart(String titulo, String eixoX, String eixoY, XYDataset dados) {

    // create the chart...
    final JFreeChart chart =
        ChartFactory.createXYLineChart(
            titulo, // chart title\
            eixoX, // x axis label
            eixoY, // y axis label
            dados, // data
            PlotOrientation.VERTICAL,
            true, // include legend
            true, // tooltips
            false // urls
            );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    // final StandardLegend legend = (StandardLegend) chart.getLegend();
    // legend.setDisplaySeriesShapes(true);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);

    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
  }
Example #28
0
  private JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart =
        ChartFactory.createXYLineChart(
            Setting.getString("/bat/isotope/graph/bg/title"), // chart title
            Setting.getString("/bat/isotope/graph/bg/x_axes"), // x axis label
            Setting.getString("/bat/isotope/graph/bg/y_axes"), // y axis label
            dataset, // data
            PlotOrientation.VERTICAL,
            false, // include legend
            true, // tooltips
            false // urls
            );

    chart.setBackgroundPaint(Setting.getColor("/bat/isotope/graph/background"));
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Setting.getColor("/bat/isotope/graph/background"));
    plot.setRangeGridlinePaint(Setting.getColor("/bat/isotope/graph/background"));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    plot.getDomainAxis().getUpperBound();
    plot.setDataset(1, Func.xYSlope(slope, plot.getDomainAxis().getUpperBound()));

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseSeriesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setBaseShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setSeriesItemLabelFont(0, fText);
    renderer.setBaseItemLabelFont(fText);
    chart.getTitle().setFont(fTitel);

    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesLinesVisible(1, true);
    renderer.setSeriesShapesVisible(1, true);

    NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRangeIncludesZero(true);
    axis.setLabelFont(fAxes);
    plot.getDomainAxis().setLabelFont(fAxes);

    return chart;
  }
Example #29
0
 private void configureRendererForCorrelativeData(XYLineAndShapeRenderer renderer) {
   renderer.setSeriesLinesVisible(1, false);
   renderer.setSeriesShapesVisible(1, true);
   renderer.setSeriesStroke(1, new BasicStroke(1.0f));
   renderer.setSeriesPaint(1, StatisticChartStyling.CORRELATIVE_POINT_PAINT);
   renderer.setSeriesFillPaint(1, StatisticChartStyling.CORRELATIVE_POINT_FILL_PAINT);
   renderer.setSeriesShape(1, StatisticChartStyling.CORRELATIVE_POINT_SHAPE);
 }
    public PrecisionErrorChart() {
      super(new BorderLayout());
      timeseriescollectionPrecisionError = new TimeSeriesCollection();

      DateAxis dateaxis = new DateAxis("Time (hh:mm:ss)");
      dateaxis.setTickLabelFont(new Font("SansSerif", 0, 12));
      dateaxis.setLabelFont(new Font("SansSerif", 0, 14));
      dateaxis.setAutoRange(true);
      dateaxis.setUpperMargin(0.3D);
      dateaxis.setTickLabelsVisible(true);

      NumberAxis numberaxis = new NumberAxis("Precision error (ms)");
      numberaxis.setTickLabelFont(new Font("SansSerif", 0, 12));
      numberaxis.setLabelFont(new Font("SansSerif", 0, 14));
      numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
      numberaxis.setRangeWithMargins(-100.0, 100.0);

      XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
      xylineandshaperenderer.setSeriesPaint(0, Color.blue);
      xylineandshaperenderer.setSeriesPaint(1, Color.red);
      xylineandshaperenderer.setSeriesPaint(2, Color.green);
      xylineandshaperenderer.setSeriesPaint(3, Color.pink);
      xylineandshaperenderer.setSeriesPaint(4, Color.magenta);
      xylineandshaperenderer.setSeriesPaint(5, Color.cyan);
      xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(0.7F, 0, 2));
      xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(0.7F, 0, 2));
      xylineandshaperenderer.setBaseShapesVisible(true);

      XYPlot xyplot =
          new XYPlot(
              timeseriescollectionPrecisionError, dateaxis, numberaxis, xylineandshaperenderer);
      xyplot.setBackgroundPaint(Color.lightGray);
      xyplot.setDomainGridlinePaint(Color.white);
      xyplot.setRangeGridlinePaint(Color.white);
      xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
      xyplot.setDomainGridlinesVisible(true);

      JFreeChart jfreechart =
          new JFreeChart("Time Precision Error", new Font("SansSerif", 1, 24), xyplot, true);
      jfreechart.setBackgroundPaint(Color.white);
      ChartPanel chartpanel = new ChartPanel(jfreechart, true);
      add(chartpanel);
    }