Пример #1
1
  private JFreeChart buildDifferenceChart(TimeSeriesCollection dataset, String title) {
    // Creat the chart
    JFreeChart chart =
        ChartFactory.createTimeSeriesChart(
            title,
            "Date",
            "Price",
            dataset,
            true, // legend
            true, // tool tips
            false // URLs
            );
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(
        new XYDifferenceRenderer(new Color(112, 128, 222), new Color(112, 128, 222), false));
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(UnitType.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));

    ValueAxis domainAxis = new DateAxis("Date");
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    plot.setDomainAxis(domainAxis);
    plot.setForegroundAlpha(0.5f);

    return chart;
  }
    @Override
    public void customize(JFreeChart chart, ReportParameters reportParameters) {

      BarRenderer barRenderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
      // barRenderer.setBaseSeriesVisible(false);//QUITA LAS BARRAS
      // barRenderer.setBaseSeriesVisibleInLegend(false);
      // barRenderer.setDrawBarOutline(false);
      barRenderer.setShadowVisible(false);
      barRenderer.setBarPainter(new CustomBarPainter());
      barRenderer.setItemMargin(0); // QUITA ESPACIOS ENTRE BARRA Y BARRA

      CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis();
      domainAxis.setUpperMargin(0);
      domainAxis.setLowerMargin(0);
      domainAxis.setCategoryMargin(0);
      domainAxis.setAxisLineVisible(false); // este es util

      Plot plot = chart.getPlot();
      // plot.setOutlineVisible(false);
      plot.setInsets(new RectangleInsets(0, 0, 0, 0)); // este sera util

      CategoryPlot categoryPlot = chart.getCategoryPlot();
      categoryPlot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
      // FAFO6categoryPlot.setRangeGridlinePaint(Color.WHITE);
      categoryPlot.setDomainGridlinesVisible(false);
      // FAFO5categoryPlot.setRangeGridlinesVisible(false);
      // categoryPlot.setBackgroundPaint(Color.white);
      categoryPlot.setOutlineVisible(false);

      ValueAxis valueAsix = categoryPlot.getRangeAxis();
      valueAsix.setAxisLineVisible(false); // este es muy util
      valueAsix.setRange(0, objDatosReporte.getIntMaxRango());
      valueAsix.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // este es muy util
    }
  /**
   * Draws a grid line against the range axis.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param axis the value axis.
   * @param dataArea the area for plotting data (not yet adjusted for any 3D effect).
   * @param value the value at which the grid line should be drawn.
   */
  public void drawRangeGridline(
      Graphics2D g2, CategoryPlot plot, ValueAxis axis, Rectangle2D dataArea, double value) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
      return;
    }

    PlotOrientation orientation = plot.getOrientation();
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    Line2D line = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
      line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());
    } else if (orientation == PlotOrientation.VERTICAL) {
      line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);
    }

    Paint paint = plot.getRangeGridlinePaint();
    if (paint == null) {
      paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT;
    }
    g2.setPaint(paint);

    Stroke stroke = plot.getRangeGridlineStroke();
    if (stroke == null) {
      stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE;
    }
    g2.setStroke(stroke);

    g2.draw(line);
  }
Пример #4
0
  /**
   * Removes a subplot from the combined chart and sends a {@link PlotChangeEvent} to all registered
   * listeners.
   *
   * @param subplot the subplot (<code>null</code> not permitted).
   */
  public void remove(XYPlot subplot) {
    if (subplot == null) {
      throw new IllegalArgumentException(" Null 'subplot' argument.");
    }
    int position = -1;
    int size = this.subplots.size();
    int i = 0;
    while (position == -1 && i < size) {
      if (this.subplots.get(i) == subplot) {
        position = i;
      }
      i++;
    }
    if (position != -1) {
      this.subplots.remove(position);
      subplot.setParent(null);
      subplot.removeChangeListener(this);
      this.totalWeight -= subplot.getWeight();

      ValueAxis domain = getDomainAxis();
      if (domain != null) {
        domain.configure();
      }
      notifyListeners(new PlotChangeEvent(this));
    }
  }
Пример #5
0
  /**
   * Adds a subplot with the specified weight and sends a {@link PlotChangeEvent} to all registered
   * listeners. The weight determines how much space is allocated to the subplot relative to all the
   * other subplots.
   *
   * <p>The domain axis for the subplot will be set to <code>null</code>. You must ensure that the
   * subplot has a non-null range axis.
   *
   * @param subplot the subplot (<code>null</code> not permitted).
   * @param weight the weight (must be >= 1).
   */
  public void add(XYPlot subplot, int weight) {

    if (subplot == null) {
      throw new IllegalArgumentException("Null 'subplot' argument.");
    }
    if (weight <= 0) {
      throw new IllegalArgumentException("Require weight >= 1.");
    }

    // store the plot and its weight
    subplot.setParent(this);
    subplot.setWeight(weight);
    subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0), false);
    subplot.setDomainAxis(null);
    subplot.addChangeListener(this);
    this.subplots.add(subplot);

    // keep track of total weights
    this.totalWeight += weight;

    ValueAxis axis = getDomainAxis();
    if (axis != null) {
      axis.configure();
    }

    notifyListeners(new PlotChangeEvent(this));
  }
    /**
     * Removes a subplot from the combined chart.
     *
     * @param subplot  the subplot (<code>null</code> not permitted).
     */
    public void remove(CategoryPlot subplot) {
        if (subplot == null) {
            throw new IllegalArgumentException(" Null 'subplot' argument.");
        }
        int position = -1;
        int size = this.subplots.size();
        int i = 0;
        while (position == -1 && i < size) {
            if (this.subplots.get(i) == subplot) {
                position = i;
            }
            i++;
        }
        if (position != -1) {
            this.subplots.remove(position);
            subplot.setParent(null);
            subplot.removeChangeListener(this);

            ValueAxis range = getRangeAxis();
            if (range != null) {
                range.configure();
            }

            ValueAxis range2 = getRangeAxis(1);
            if (range2 != null) {
                range2.configure();
            }
            fireChangeEvent();
        }
    }
Пример #7
0
  /**
   * Creates and returns a time series chart.
   *
   * <p>A time series chart is an XYPlot with a date axis (horizontal) and a number axis (vertical),
   * and each data item is connected with a line.
   *
   * <p>Note that you can supply a TimeSeriesCollection to this method, as it implements the
   * XYDataset interface.
   *
   * @param title the chart title.
   * @param timeAxisLabel a label for the time axis.
   * @param valueAxisLabel a label for the value axis.
   * @param data the dataset for the chart.
   * @param legend a flag specifying whether or not a legend is required.
   * @param tooltips configure chart to generate tool tips?
   * @param urls configure chart to generate URLs?
   * @return a time series chart.
   */
  public static JFreeChart createTimeSeriesChart(
      String title,
      java.awt.Font titleFont,
      String timeAxisLabel,
      String valueAxisLabel,
      XYDataset data,
      boolean legend,
      boolean tooltips,
      boolean urls) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    timeAxis.setLowerMargin(0.02); // reduce the default margins on the time axis
    timeAxis.setUpperMargin(0.02);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false); // override default
    XYPlot plot = new XYPlot(data, timeAxis, valueAxis, null);

    XYToolTipGenerator tooltipGenerator = null;
    if (tooltips) {
      tooltipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
      // new StandardXYToolTipGenerator(DateFormat.getDateInstance());
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
      urlGenerator = new StandardXYURLGenerator();
    }

    plot.setRenderer(
        new StandardXYItemRenderer(StandardXYItemRenderer.LINES, tooltipGenerator, urlGenerator));

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;
  }
Пример #8
0
  /**
   * Draws the annotation.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param dataArea the data area.
   * @param domainAxis the domain axis.
   * @param rangeAxis the range axis.
   * @param rendererIndex the renderer index.
   * @param info if supplied, this info object will be populated with entity information.
   */
  public void draw(
      Graphics2D g2,
      XYPlot plot,
      Rectangle2D dataArea,
      ValueAxis domainAxis,
      ValueAxis rangeAxis,
      int rendererIndex,
      PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge =
        Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge =
        Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
    float j2DX = (float) domainAxis.valueToJava2D(this.x, dataArea, domainEdge);
    float j2DY = (float) rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge);
    Rectangle2D area =
        new Rectangle2D.Double(
            j2DX - this.width / 2.0, j2DY - this.height / 2.0, this.width, this.height);
    this.drawable.draw(g2, area);
    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
      addEntity(info, area, rendererIndex, toolTip, url);
    }
  }
Пример #9
0
  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));
  }
  /** Replaces the dataset and checks that the data range is as expected. */
  public void testReplaceDataset() {

    // create a dataset...
    Number[][] data =
        new Integer[][] {
          {new Integer(-30), new Integer(-20)},
          {new Integer(-10), new Integer(10)},
          {new Integer(20), new Integer(30)}
        };

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    this.chart.getCategoryPlot().setDataset(newData);
    assertEquals(true, l.flag);
    ValueAxis axis = this.chart.getCategoryPlot().getRangeAxis();
    Range range = axis.getRange();
    assertTrue(
        "Expecting the lower bound of the range to be around -30: " + range.getLowerBound(),
        range.getLowerBound() <= -30);
    assertTrue(
        "Expecting the upper bound of the range to be around 30: " + range.getUpperBound(),
        range.getUpperBound() >= 30);
  }
Пример #11
0
  @SuppressWarnings("deprecation")
  private static JFreeChart createChart(
      int[] dataTitles, String title, String xaxisName, String yaxisName) {
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    timeSeries = new TimeSeries[dataTitles.length];

    for (int i = 0; i < timeSeries.length; i++) {
      timeSeries[i] = new TimeSeries("No." + dataTitles[i], Millisecond.class);
      timeseriescollection.addSeries(timeSeries[i]);
    }

    JFreeChart jfreechart =
        ChartFactory.createTimeSeriesChart(
            title, xaxisName, yaxisName, timeseriescollection, true, true, false);
    XYPlot xyplot = jfreechart.getXYPlot();
    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setAutoRange(true);
    long t = 7200;
    valueaxis.setFixedAutoRange(t * 1000D);

    valueaxis = xyplot.getRangeAxis();
    // valueaxis.setRange(0.0D,200D);

    return jfreechart;
  }
Пример #12
0
 /**
  * Handles a state change event.
  *
  * @param event the event.
  */
 public void stateChanged(ChangeEvent event) {
   int value = this.slider.getValue();
   XYPlot plot = this.chart.getXYPlot();
   ValueAxis domainAxis = plot.getDomainAxis();
   Range range = domainAxis.getRange();
   double c = domainAxis.getLowerBound() + (value / 100.0) * range.getLength();
   plot.setDomainCrosshairValue(c);
 }
Пример #13
0
 /**
  * 更新图表显示
  *
  * @param chart
  */
 private void updatePlot(JFreeChart chart) {
   // 图表
   CategoryPlot categoryPlot = chart.getCategoryPlot();
   // y轴
   ValueAxis valueAxis = categoryPlot.getRangeAxis();
   // Y轴数据范围
   valueAxis.setRangeAboutValue(200, 1000);
 }
Пример #14
0
 public void stateChanged(ChangeEvent changeevent) {
   int i = slider.getValue();
   XYPlot xyplot = (XYPlot) chart.getPlot();
   ValueAxis valueaxis = xyplot.getDomainAxis();
   Range range = valueaxis.getRange();
   double d = valueaxis.getLowerBound() + ((double) i / 100D) * range.getLength();
   xyplot.setDomainCrosshairValue(d);
 }
Пример #15
0
  /**
   * Calculates the axis space required.
   *
   * @param g2 the graphics device.
   * @param plotArea the plot area.
   * @return The space.
   */
  protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) {

    AxisSpace space = new AxisSpace();
    PlotOrientation orientation = getOrientation();

    // work out the space required by the domain axis...
    AxisSpace fixed = getFixedDomainAxisSpace();
    if (fixed != null) {
      if (orientation == PlotOrientation.HORIZONTAL) {
        space.setLeft(fixed.getLeft());
        space.setRight(fixed.getRight());
      } else if (orientation == PlotOrientation.VERTICAL) {
        space.setTop(fixed.getTop());
        space.setBottom(fixed.getBottom());
      }
    } else {
      ValueAxis xAxis = getDomainAxis();
      RectangleEdge xEdge = Plot.resolveDomainAxisLocation(getDomainAxisLocation(), orientation);
      if (xAxis != null) {
        space = xAxis.reserveSpace(g2, this, plotArea, xEdge, space);
      }
    }

    Rectangle2D adjustedPlotArea = space.shrink(plotArea, null);

    // work out the maximum height or width of the non-shared axes...
    int n = this.subplots.size();
    this.subplotAreas = new Rectangle2D[n];
    double x = adjustedPlotArea.getX();
    double y = adjustedPlotArea.getY();
    double usableSize = 0.0;
    if (orientation == PlotOrientation.HORIZONTAL) {
      usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1);
    } else if (orientation == PlotOrientation.VERTICAL) {
      usableSize = adjustedPlotArea.getHeight() - this.gap * (n - 1);
    }

    for (int i = 0; i < n; i++) {
      XYPlot plot = (XYPlot) this.subplots.get(i);

      // calculate sub-plot area
      if (orientation == PlotOrientation.HORIZONTAL) {
        double w = usableSize * plot.getWeight() / this.totalWeight;
        this.subplotAreas[i] = new Rectangle2D.Double(x, y, w, adjustedPlotArea.getHeight());
        x = x + w + this.gap;
      } else if (orientation == PlotOrientation.VERTICAL) {
        double h = usableSize * plot.getWeight() / this.totalWeight;
        this.subplotAreas[i] = new Rectangle2D.Double(x, y, adjustedPlotArea.getWidth(), h);
        y = y + h + this.gap;
      }

      AxisSpace subSpace = plot.calculateRangeAxisSpace(g2, this.subplotAreas[i], null);
      space.ensureAtLeast(subSpace);
    }

    return space;
  }
Пример #16
0
 private void updateScalingOfXAxis() {
   final boolean logScaled = scatterPlotModel.xAxisLogScaled;
   final ValueAxis oldAxis = getPlot().getDomainAxis();
   ValueAxis newAxis = StatisticChartStyling.updateScalingOfAxis(logScaled, oldAxis, false);
   oldAxis.removeChangeListener(domainAxisChangeListener);
   newAxis.addChangeListener(domainAxisChangeListener);
   getPlot().setDomainAxis(newAxis);
   finishScalingUpdate(xAxisRangeControl, newAxis, oldAxis);
 }
Пример #17
0
  /**
   * Initialises the renderer and returns a state object that should be passed to all subsequent
   * calls to the drawItem() method. Here we calculate the Java2D y-coordinate for zero, since all
   * the bars have their bases fixed at zero.
   *
   * @param g2 the graphics device.
   * @param dataArea the area inside the axes.
   * @param plot the plot.
   * @param dataset the data.
   * @param info an optional info collection object to return data back to the caller.
   * @return A state object.
   */
  @Override
  public XYItemRendererState initialise(
      Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset dataset, PlotRenderingInfo info) {

    XYBarRendererState state = new XYBarRendererState(info);
    ValueAxis rangeAxis = plot.getRangeAxisForDataset(plot.indexOf(dataset));
    state.setG2Base(rangeAxis.valueToJava2D(this.base, dataArea, plot.getRangeAxisEdge()));
    return state;
  }
Пример #18
0
 /**
  * Sets the properties of the specified axis to match the properties defined on this panel.
  *
  * @param axis the axis.
  */
 public void setAxisProperties(Axis axis) {
   super.setAxisProperties(axis);
   ValueAxis valueAxis = (ValueAxis) axis;
   valueAxis.setAutoRange(this.autoRange);
   if (!this.autoRange) {
     valueAxis.setRange(this.minimumValue, this.maximumValue);
   }
   valueAxis.setAutoTickUnitSelection(this.autoTickUnitSelection);
 }
  /**
   * Constructs a new demonstration application.
   *
   * @param title the frame title.
   */
  public DynamicDataDemo3(String title) {

    super(title);

    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.datasets = new TimeSeriesCollection[SUBPLOT_COUNT];

    for (int i = 0; i < SUBPLOT_COUNT; i++) {
      this.lastValue[i] = 100.0;
      TimeSeries series = new TimeSeries("Random " + i, Millisecond.class);
      this.datasets[i] = new TimeSeriesCollection(series);
      NumberAxis rangeAxis = new NumberAxis("Y" + i);
      rangeAxis.setAutoRangeIncludesZero(false);
      XYPlot subplot = new XYPlot(this.datasets[i], null, rangeAxis, new StandardXYItemRenderer());
      subplot.setBackgroundPaint(Color.lightGray);
      subplot.setDomainGridlinePaint(Color.white);
      subplot.setRangeGridlinePaint(Color.white);
      plot.add(subplot);
    }

    JFreeChart chart = new JFreeChart("Dynamic Data Demo 3", plot);
    chart.getLegend().setAnchor(Legend.EAST);
    chart.setBorderPaint(Color.black);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds

    JPanel content = new JPanel(new BorderLayout());

    ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    JPanel buttonPanel = new JPanel(new FlowLayout());

    for (int i = 0; i < SUBPLOT_COUNT; i++) {
      JButton button = new JButton("Series " + i);
      button.setActionCommand("ADD_DATA_" + i);
      button.addActionListener(this);
      buttonPanel.add(button);
    }
    JButton buttonAll = new JButton("ALL");
    buttonAll.setActionCommand("ADD_ALL");
    buttonAll.addActionListener(this);
    buttonPanel.add(buttonAll);

    content.add(buttonPanel, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 470));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(content);
  }
Пример #20
0
  /**
   * Draws the item (first pass). This method draws the lines connecting the items.
   *
   * @param g2 the graphics device.
   * @param state the renderer state.
   * @param dataArea the area within which the data is being drawn.
   * @param plot the plot (can be used to obtain standard color information etc).
   * @param domainAxis the domain axis.
   * @param rangeAxis the range axis.
   * @param dataset the dataset.
   * @param pass the pass.
   * @param series the series index (zero-based).
   * @param item the item index (zero-based).
   */
  protected void drawPrimaryLine(
      XYItemRendererState state,
      Graphics2D g2,
      XYPlot plot,
      XYDataset dataset,
      int pass,
      int series,
      int item,
      ValueAxis domainAxis,
      ValueAxis rangeAxis,
      Rectangle2D dataArea) {
    if (item == 0) {
      return;
    }

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
      return;
    }

    double x0 = dataset.getXValue(series, item - 1);
    double y0 = dataset.getYValue(series, item - 1);
    if (Double.isNaN(y0) || Double.isNaN(x0)) {
      return;
    }

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    // only draw if we have good values
    if (Double.isNaN(transX0)
        || Double.isNaN(transY0)
        || Double.isNaN(transX1)
        || Double.isNaN(transY1)) {
      return;
    }

    PlotOrientation orientation = plot.getOrientation();
    boolean visible;
    if (orientation == PlotOrientation.HORIZONTAL) {
      state.workingLine.setLine(transY0, transX0, transY1, transX1);
    } else if (orientation == PlotOrientation.VERTICAL) {
      state.workingLine.setLine(transX0, transY0, transX1, transY1);
    }
    visible = LineUtilities.clipLine(state.workingLine, dataArea);
    if (visible) {
      drawFirstPassShape(g2, pass, series, item, state.workingLine);
    }
  }
Пример #21
0
  /**
   * Draws the annotation. This method is usually called by the {@link XYPlot} class, you shouldn't
   * need to call it directly.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param dataArea the data area.
   * @param domainAxis the domain axis.
   * @param rangeAxis the range axis.
   * @param rendererIndex the renderer index.
   * @param info the plot rendering info.
   */
  public void draw(
      Graphics2D g2,
      XYPlot plot,
      Rectangle2D dataArea,
      ValueAxis domainAxis,
      ValueAxis rangeAxis,
      int rendererIndex,
      PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge =
        Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge =
        Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);

    // compute transform matrix elements via sample points. Assume no
    // rotation or shear.
    Rectangle2D bounds = this.shape.getBounds2D();
    double x0 = bounds.getMinX();
    double x1 = bounds.getMaxX();
    double xx0 = domainAxis.valueToJava2D(x0, dataArea, domainEdge);
    double xx1 = domainAxis.valueToJava2D(x1, dataArea, domainEdge);
    double m00 = (xx1 - xx0) / (x1 - x0);
    double m02 = xx0 - x0 * m00;

    double y0 = bounds.getMaxY();
    double y1 = bounds.getMinY();
    double yy0 = rangeAxis.valueToJava2D(y0, dataArea, rangeEdge);
    double yy1 = rangeAxis.valueToJava2D(y1, dataArea, rangeEdge);
    double m11 = (yy1 - yy0) / (y1 - y0);
    double m12 = yy0 - m11 * y0;

    //  create transform & transform shape
    Shape s = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
      AffineTransform t1 = new AffineTransform(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
      AffineTransform t2 = new AffineTransform(m11, 0.0f, 0.0f, m00, m12, m02);
      s = t1.createTransformedShape(this.shape);
      s = t2.createTransformedShape(s);
    } else if (orientation == PlotOrientation.VERTICAL) {
      AffineTransform t = new AffineTransform(m00, 0, 0, m11, m02, m12);
      s = t.createTransformedShape(this.shape);
    }

    if (this.fillPaint != null) {
      g2.setPaint(this.fillPaint);
      g2.fill(s);
    }

    if (this.stroke != null && this.outlinePaint != null) {
      g2.setPaint(this.outlinePaint);
      g2.setStroke(this.stroke);
      g2.draw(s);
    }
    addEntity(info, s, rendererIndex, getToolTipText(), getURL());
  }
Пример #22
0
 private JFreeChart createChart(XYDataset xydataset) {
   JFreeChart jfreechart =
       ChartFactory.createTimeSeriesChart(
           "Serialization Test 1", "Time", "Value", xydataset, true, true, false);
   XYPlot xyplot = (XYPlot) jfreechart.getPlot();
   ValueAxis valueaxis = xyplot.getDomainAxis();
   valueaxis.setAutoRange(true);
   valueaxis.setFixedAutoRange(60000D);
   return jfreechart;
 }
  /**
   * Update background, tick and gridline colors
   *
   * @param cfg cfg[0] Background, cfg[1] Chart background, cfg[2] y cfg[3] gridline
   */
  public void updateChartColors(String[] cfg) {
    strBackgroundColor = cfg[0];
    for (Node le : legendFrame.getChildren()) {
      if (le instanceof LegendAxis) {
        le.setStyle("-fx-background-color:" + strBackgroundColor);
        ((LegendAxis) le).selected = false;
      }
    }
    chart.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)));
    chartPanel.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(
                scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)))));
    chartPanel.setBackground(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)));

    legendFrame.setStyle("marco: " + strBackgroundColor + ";-fx-background-color: marco;");

    strChartBackgroundColor = cfg[1];
    ;
    plot.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strChartBackgroundColor)));

    for (Node le : legendFrame.getChildren()) {
      if (le instanceof LegendAxis) {
        le.setStyle("-fx-background-color:" + strBackgroundColor);
        ((LegendAxis) le).selected = false;
        for (Node nn : ((LegendAxis) le).getChildren()) {
          if (nn instanceof Label) {
            ((Label) nn)
                .setStyle(
                    "fondo: "
                        + strChartBackgroundColor
                        + ";-fx-background-color: fondo;-fx-text-fill: ladder(fondo, white 49%, black 50%);-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: "
                        + String.valueOf(fontSize)
                        + "px");
          }
        }
      }
    }

    strGridlineColor = cfg[2];
    ;
    plot.setDomainGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor)));
    plot.setRangeGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor)));

    strTickColor = cfg[3];
    ;
    abcissaAxis.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    abcissaAxis.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    for (NumberAxis ejeOrdenada : AxesList) {
      ejeOrdenada.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
      ejeOrdenada.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    }
  }
    /**
     * Draws the plot on a Java 2D graphics device (such as the screen or a
     * printer).  Will perform all the placement calculations for each
     * sub-plots and then tell these to draw themselves.
     *
     * @param g2  the graphics device.
     * @param area  the area within which the plot (including axis labels)
     *              should be drawn.
     * @param anchor  the anchor point (<code>null</code> permitted).
     * @param parentState  the parent state.
     * @param info  collects information about the drawing (<code>null</code>
     *              permitted).
     */
    public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor,
                     PlotState parentState,
                     PlotRenderingInfo info) {

        // set up info collection...
        if (info != null) {
            info.setPlotArea(area);
        }

        // adjust the drawing area for plot insets (if any)...
        RectangleInsets insets = getInsets();
        insets.trim(area);

        // calculate the data area...
        AxisSpace space = calculateAxisSpace(g2, area);
        Rectangle2D dataArea = space.shrink(area, null);

        // set the width and height of non-shared axis of all sub-plots
        setFixedDomainAxisSpaceForSubplots(space);

        // draw the shared axis
        ValueAxis axis = getRangeAxis();
        RectangleEdge rangeEdge = getRangeAxisEdge();
        double cursor = RectangleEdge.coordinate(dataArea, rangeEdge);
        AxisState state = axis.draw(g2, cursor, area, dataArea, rangeEdge,
                info);
        if (parentState == null) {
            parentState = new PlotState();
        }
        parentState.getSharedAxisStates().put(axis, state);

        // draw all the charts
        for (int i = 0; i < this.subplots.size(); i++) {
            CategoryPlot plot = (CategoryPlot) this.subplots.get(i);
            PlotRenderingInfo subplotInfo = null;
            if (info != null) {
                subplotInfo = new PlotRenderingInfo(info.getOwner());
                info.addSubplotInfo(subplotInfo);
            }
            Point2D subAnchor = null;
            if (anchor != null && this.subplotArea[i].contains(anchor)) {
                subAnchor = anchor;
            }
            plot.draw(g2, this.subplotArea[i], subAnchor, parentState,
                    subplotInfo);
        }

        if (info != null) {
            info.setDataArea(dataArea);
        }

    }
Пример #25
0
  /**
   * Standard constructor: builds a property panel for the specified axis.
   *
   * @param axis the axis, which should be changed.
   */
  public DefaultValueAxisEditor(ValueAxis axis) {

    super(axis);

    this.autoRange = axis.isAutoRange();
    this.minimumValue = axis.getLowerBound();
    this.maximumValue = axis.getUpperBound();
    this.autoTickUnitSelection = axis.isAutoTickUnitSelection();

    this.gridPaintSample = new PaintSample(Color.blue);
    this.gridStrokeSample = new StrokeSample(new BasicStroke(1.0f));

    this.availableStrokeSamples = new StrokeSample[3];
    this.availableStrokeSamples[0] = new StrokeSample(new BasicStroke(1.0f));
    this.availableStrokeSamples[1] = new StrokeSample(new BasicStroke(2.0f));
    this.availableStrokeSamples[2] = new StrokeSample(new BasicStroke(3.0f));

    JTabbedPane other = getOtherTabs();

    JPanel range = new JPanel(new LCBLayout(3));
    range.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

    range.add(new JPanel());
    this.autoRangeCheckBox =
        new JCheckBox(localizationResources.getString("Auto-adjust_range"), this.autoRange);
    this.autoRangeCheckBox.setActionCommand("AutoRangeOnOff");
    this.autoRangeCheckBox.addActionListener(this);
    range.add(this.autoRangeCheckBox);
    range.add(new JPanel());

    range.add(new JLabel(localizationResources.getString("Minimum_range_value")));
    this.minimumRangeValue = new JTextField(Double.toString(this.minimumValue));
    this.minimumRangeValue.setEnabled(!this.autoRange);
    this.minimumRangeValue.setActionCommand("MinimumRange");
    this.minimumRangeValue.addActionListener(this);
    this.minimumRangeValue.addFocusListener(this);
    range.add(this.minimumRangeValue);
    range.add(new JPanel());

    range.add(new JLabel(localizationResources.getString("Maximum_range_value")));
    this.maximumRangeValue = new JTextField(Double.toString(this.maximumValue));
    this.maximumRangeValue.setEnabled(!this.autoRange);
    this.maximumRangeValue.setActionCommand("MaximumRange");
    this.maximumRangeValue.addActionListener(this);
    this.maximumRangeValue.addFocusListener(this);
    range.add(this.maximumRangeValue);
    range.add(new JPanel());

    other.add(localizationResources.getString("Range"), range);

    other.add(localizationResources.getString("TickUnit"), createTickUnitPanel());
  }
    /**
     * Provides serialization support.
     *
     * @param stream  the input stream.
     *
     * @throws IOException  if there is an I/O error.
     * @throws ClassNotFoundException  if there is a classpath problem.
     */
    private void readObject(ObjectInputStream stream)
        throws IOException, ClassNotFoundException {

        stream.defaultReadObject();

        // the range axis is deserialized before the subplots, so its value
        // range is likely to be incorrect...
        ValueAxis rangeAxis = getRangeAxis();
        if (rangeAxis != null) {
            rangeAxis.configure();
        }

    }
  /**
   * Draws the block representing the specified item.
   *
   * @param g2 the graphics device.
   * @param state the state.
   * @param dataArea the data area.
   * @param info the plot rendering info.
   * @param plot the plot.
   * @param domainAxis the x-axis.
   * @param rangeAxis the y-axis.
   * @param dataset the dataset.
   * @param series the series index.
   * @param item the item index.
   * @param crosshairState the crosshair state.
   * @param pass the pass index.
   */
  public void drawItem(
      Graphics2D g2,
      XYItemRendererState state,
      Rectangle2D dataArea,
      PlotRenderingInfo info,
      XYPlot plot,
      ValueAxis domainAxis,
      ValueAxis rangeAxis,
      XYDataset dataset,
      int series,
      int item,
      CrosshairState crosshairState,
      int pass) {

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double z = 0.0;
    if (dataset instanceof XYZDataset) {
      z = ((XYZDataset) dataset).getZValue(series, item);
    }
    Paint p = this.paintScale.getPaint(z);
    double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea, plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea, plot.getRangeAxisEdge());
    double xx1 =
        domainAxis.valueToJava2D(
            x + this.blockWidth + this.xOffset, dataArea, plot.getDomainAxisEdge());
    double yy1 =
        rangeAxis.valueToJava2D(
            y + this.blockHeight + this.yOffset, dataArea, plot.getRangeAxisEdge());
    Rectangle2D block;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation.equals(PlotOrientation.HORIZONTAL)) {
      block =
          new Rectangle2D.Double(
              Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0), Math.abs(xx0 - xx1));
    } else {
      block =
          new Rectangle2D.Double(
              Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0), Math.abs(yy1 - yy0));
    }
    g2.setPaint(p);
    g2.fill(block);
    g2.setStroke(new BasicStroke(1.0f));
    g2.draw(block);

    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
      addEntity(entities, block, dataset, series, item, 0.0, 0.0);
    }
  }
Пример #28
0
    /** Creates a new self-contained demo panel. */
    public MyDemoPanel() {
      super(new BorderLayout());
      this.series1 = new TimeSeries("Random 1");
      this.series2 = new TimeSeries("Random 2");
      TimeSeriesCollection dataset1 = new TimeSeriesCollection(this.series1);
      TimeSeriesCollection dataset2 = new TimeSeriesCollection(this.series2);
      JFreeChart chart =
          ChartFactory.createTimeSeriesChart(
              "Dynamic Data Demo 2", "Time", "Value", dataset1, true, true, false);
      // addChart(chart);

      XYPlot plot = (XYPlot) chart.getPlot();
      ValueAxis axis = plot.getDomainAxis();
      axis.setAutoRange(true);
      axis.setFixedAutoRange(10000.0); // 10 seconds

      plot.setDataset(1, dataset2);
      NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2");
      rangeAxis2.setAutoRangeIncludesZero(false);
      plot.setRenderer(1, new DefaultXYItemRenderer());
      plot.setRangeAxis(1, rangeAxis2);
      plot.mapDatasetToRangeAxis(1, 1);

      ChartUtilities.applyCurrentTheme(chart);

      ChartPanel chartPanel = new ChartPanel(chart);
      // add(chartPanel);

      JButton button1 = new JButton("Add To Series 1");
      button1.setActionCommand("ADD_DATA_1");
      button1.addActionListener(this);

      JButton button2 = new JButton("Add To Series 2");
      button2.setActionCommand("ADD_DATA_2");
      button2.addActionListener(this);

      JButton button3 = new JButton("Add To Both");
      button3.setActionCommand("ADD_BOTH");
      button3.addActionListener(this);

      JPanel buttonPanel = new JPanel(new FlowLayout());
      buttonPanel.setBackground(Color.white);
      buttonPanel.add(button1);
      buttonPanel.add(button2);
      buttonPanel.add(button3);

      // add(buttonPanel, BorderLayout.SOUTH);
      chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    }
Пример #29
0
  /**
   * Draws a range marker.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param axis the value axis.
   * @param marker the marker.
   * @param dataArea the area for plotting data (not including 3D effect).
   */
  @Override
  public void drawRangeMarker(
      Graphics2D g2, CategoryPlot plot, ValueAxis axis, Marker marker, Rectangle2D dataArea) {

    Rectangle2D adjusted =
        new Rectangle2D.Double(
            dataArea.getX(),
            dataArea.getY() + getYOffset(),
            dataArea.getWidth() - getXOffset(),
            dataArea.getHeight() - getYOffset());

    if (marker instanceof ValueMarker) {
      ValueMarker vm = (ValueMarker) marker;
      double value = vm.getValue();
      Range range = axis.getRange();
      if (!range.contains(value)) {
        return;
      }

      GeneralPath path = null;
      PlotOrientation orientation = plot.getOrientation();
      if (orientation == PlotOrientation.HORIZONTAL) {
        float x = (float) axis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge());
        float y = (float) adjusted.getMaxY();
        path = new GeneralPath();
        path.moveTo(x, y);
        path.lineTo((float) (x + getXOffset()), y - (float) getYOffset());
        path.lineTo((float) (x + getXOffset()), (float) (adjusted.getMinY() - getYOffset()));
        path.lineTo(x, (float) adjusted.getMinY());
        path.closePath();
      } else if (orientation == PlotOrientation.VERTICAL) {
        float y = (float) axis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge());
        float x = (float) dataArea.getX();
        path = new GeneralPath();
        path.moveTo(x, y);
        path.lineTo(x + (float) this.xOffset, y - (float) this.yOffset);
        path.lineTo((float) (adjusted.getMaxX() + this.xOffset), y - (float) this.yOffset);
        path.lineTo((float) (adjusted.getMaxX()), y);
        path.closePath();
      }
      g2.setPaint(marker.getPaint());
      g2.fill(path);
      g2.setPaint(marker.getOutlinePaint());
      g2.draw(path);
    } else {
      super.drawRangeMarker(g2, plot, axis, marker, adjusted);
      // TODO: draw the interval marker with a 3D effect
    }
  }
  /**
   * Pans all domain axes by the specified percentage.
   *
   * @param panRange the distance to pan (as a percentage of the axis length).
   * @param info the plot info
   * @param source the source point where the pan action started.
   * @since 1.0.15
   */
  @Override
  public void panDomainAxes(double panRange, PlotRenderingInfo info, Point2D source) {

    XYPlot subplot = findSubplot(info, source);
    if (subplot != null) {
      PlotRenderingInfo subplotInfo = info.getSubplotInfo(info.getSubplotIndex(source));
      if (subplotInfo == null) {
        return;
      }

      for (int i = 0; i < subplot.getDomainAxisCount(); i++) {
        ValueAxis domainAxis = subplot.getDomainAxis(i);
        domainAxis.pan(panRange);
      }
    }
  }