Package org.jfree.chart.plot

Examples of org.jfree.chart.plot.XYPlot


        ds.addSeries(series);

        JFreeChart scatterPlot = ChartFactory.createScatterPlot("Regression",
                "X", "Y", ds, PlotOrientation.HORIZONTAL, true, false, false);

        XYPlot plot = (XYPlot) scatterPlot.getPlot();

        double[] regression = Regression.getOLSRegression(ds, 0);

        // regression line points

        double v1 = regression[0] + regression[1] * 1;
        double v2 = regression[0] + regression[1] * 6;

        DefaultXYDataset ds2 = new DefaultXYDataset();
        ds2.addSeries("regline", new double[][] { new double[] { 1, 6 },
                new double[] { v1, v2 } });
        plot.setDataset(1, ds2);
        plot.setRenderer(1, new XYLineAndShapeRenderer(true, false));

        JFreeChart c = new JFreeChart(plot);

        return new JFreeChartWrapper(c);
    }
View Full Code Here


  public LegendItem getLegendItem(final int datasetIndex, final int series)
  {

    // if the renderer isn't assigned to a plot, then we don't have a
    // dataset...
    final XYPlot plot = getPlot();
    if (plot == null)
    {
      return null;
    }

    final XYDataset dataset = plot.getDataset(datasetIndex);
    if (dataset == null)
    {
      return null;
    }
View Full Code Here

  protected void configureChart(final JFreeChart chart)
  {
    super.configureChart(chart);

    final XYPlot plot = chart.getXYPlot();
    final XYItemRenderer renderer = plot.getRenderer();

    if (StringUtils.isEmpty(getTooltipFormula()) == false)
    {
      renderer.setBaseToolTipGenerator(new FormulaXYZTooltipGenerator(getRuntime(), getTooltipFormula()));
    }
    if (StringUtils.isEmpty(getUrlFormula()) == false)
    {
      renderer.setURLGenerator(new FormulaXYZURLGenerator(getRuntime(), getUrlFormula()));
    }

    renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(Boolean.TRUE.equals(getItemsLabelVisible()));
    if (getItemLabelFont() != null)
    {
      renderer.setBaseItemLabelFont(getItemLabelFont());
    }

    plot.setOrientation(computePlotOrientation());

    // May be an axis that supports dates
    final ValueAxis domainAxis = plot.getDomainAxis();
    if (domainAxis instanceof NumberAxis)
    {
      final NumberAxis numberAxis = (NumberAxis) domainAxis;
      numberAxis.setAutoRangeIncludesZero(isDomainIncludesZero());
      numberAxis.setAutoRangeStickyZero(isDomainStickyZero());
      if (getDomainPeriodCount() > 0)
      {
        if (getDomainTickFormat() != null)
        {
          numberAxis.setTickUnit(new NumberTickUnit(getDomainPeriodCount(), getDomainTickFormat()));
        }
        else if (getDomainTickFormatString() != null)
        {
          final FastDecimalFormat formatter = new FastDecimalFormat
              (getDomainTickFormatString(), getResourceBundleFactory().getLocale());
          numberAxis.setTickUnit(new FastNumberTickUnit(getDomainPeriodCount(), formatter));
        }
        else
        {
          numberAxis.setTickUnit(new FastNumberTickUnit(getDomainPeriodCount()));
        }
      }
      else
      {
        if (getDomainTickFormat() != null)
        {
          numberAxis.setNumberFormatOverride(getDomainTickFormat());
        }
        else if (getDomainTickFormatString() != null)
        {
          final DecimalFormat formatter = new DecimalFormat
              (getDomainTickFormatString(), new DecimalFormatSymbols(getResourceBundleFactory().getLocale()));
          numberAxis.setNumberFormatOverride(formatter);
        }
      }
    }
    else if (domainAxis instanceof DateAxis)
    {
      final DateAxis numberAxis = (DateAxis) domainAxis;

      if (getDomainPeriodCount() > 0 && getDomainTimePeriod() != null)
      {
        if (getDomainTickFormatString() != null)
        {
          final SimpleDateFormat formatter = new SimpleDateFormat
              (getDomainTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale()));
          numberAxis.setTickUnit
              (new DateTickUnit(getDateUnitAsInt(getDomainTimePeriod()), (int) getDomainPeriodCount(), formatter));
        }
        else
        {
          numberAxis.setTickUnit
              (new DateTickUnit(getDateUnitAsInt(getDomainTimePeriod()), (int) getDomainPeriodCount()));
        }
      }
    }

    if (domainAxis != null)
    {
      domainAxis.setLabel(getDomainTitle());
      if (getDomainTitleFont() != null)
      {
        domainAxis.setLabelFont(getDomainTitleFont());
      }
      domainAxis.setVerticalTickLabels(isDomainVerticalTickLabels());
      if (getDomainTickFont() != null)
      {
        domainAxis.setTickLabelFont(getDomainTickFont());
      }
      final int level = getRuntime().getProcessingContext().getCompatibilityLevel();
      if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8))
      {
        if (getDomainMinimum() != 0)
        {
          domainAxis.setLowerBound(getDomainMinimum());
        }
        if (getDomainMaximum() != 1)
        {
          domainAxis.setUpperBound(getDomainMaximum());
        }
        if (getDomainMinimum() == 0 && getDomainMaximum() == 0)
        {
          domainAxis.setLowerBound(0);
          domainAxis.setUpperBound(1);
          domainAxis.setAutoRange(true);
        }
      }
      else
      {
        domainAxis.setLowerBound(getDomainMinimum());
        domainAxis.setUpperBound(getDomainMaximum());
        domainAxis.setAutoRange(isDomainAxisAutoRange());
      }
    }

    final ValueAxis rangeAxis = plot.getRangeAxis();
    if (rangeAxis instanceof NumberAxis)
    {
      final NumberAxis numberAxis = (NumberAxis) rangeAxis;
      numberAxis.setAutoRangeIncludesZero(isRangeIncludesZero());
      numberAxis.setAutoRangeStickyZero(isRangeStickyZero());
View Full Code Here

  protected void configureChart(final JFreeChart chart)
  {
    super.configureChart(chart);

    final XYPlot xypl = chart.getXYPlot();
    final XYItemRenderer renderer = xypl.getRenderer();
    renderer.setStroke(translateLineStyle(lineWidth, lineStyle));
    if (renderer instanceof XYLineAndShapeRenderer)
    {
      final XYLineAndShapeRenderer renderer1 = (XYLineAndShapeRenderer) renderer;
      renderer1.setShapesVisible(isMarkersVisible());
View Full Code Here

  protected void configureChart(final JFreeChart chart)
  {
    super.configureChart(chart);

    final XYPlot plot = chart.getXYPlot();

    if (isSharedRangeAxis() == false)
    {
      final ValueAxis linesAxis = plot.getRangeAxis(1);
      if (linesAxis instanceof NumberAxis)
      {
        final NumberAxis numberAxis = (NumberAxis) linesAxis;
        numberAxis.setAutoRangeIncludesZero(isLineAxisIncludesZero());
        numberAxis.setAutoRangeStickyZero(isLineAxisStickyZero());

        if (getLinePeriodCount() > 0)
        {
          if (getLineTicksLabelFormat() != null)
          {
            final FastDecimalFormat formatter = new FastDecimalFormat
                (getLineTicksLabelFormat(), getResourceBundleFactory().getLocale());
            numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount(), formatter));
          }
          else
          {
            numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount()));
          }
        }
        else
        {
          if (getLineTicksLabelFormat() != null)
          {
            final DecimalFormat formatter = new DecimalFormat
                (getLineTicksLabelFormat(), new DecimalFormatSymbols(getResourceBundleFactory().getLocale()));
            numberAxis.setNumberFormatOverride(formatter);
          }
        }
      }
      else if (linesAxis instanceof DateAxis)
      {
        final DateAxis numberAxis = (DateAxis) linesAxis;

        if (getLinePeriodCount() > 0 && getLineTimePeriod() != null)
        {
          if (getLineTicksLabelFormat() != null)
          {
            final SimpleDateFormat formatter = new SimpleDateFormat
                (getLineTicksLabelFormat(), new DateFormatSymbols(getResourceBundleFactory().getLocale()));
            numberAxis.setTickUnit
                (new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()), (int) getLinePeriodCount(), formatter));
          }
          else
          {
            numberAxis.setTickUnit
                (new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()), (int) getLinePeriodCount()));
          }
        }
        else if (getRangeTickFormatString() != null)
        {
          final SimpleDateFormat formatter = new SimpleDateFormat
              (getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale()));
          numberAxis.setDateFormatOverride(formatter);
        }
      }

      if (linesAxis != null)
      {
        final Font labelFont = Font.decode(getLabelFont());
        linesAxis.setLabelFont(labelFont);
        linesAxis.setTickLabelFont(labelFont);

        if (getLineTitleFont() != null)
        {
          linesAxis.setLabelFont(getLineTitleFont());
        }
        if (getLineTickFont() != null)
        {
          linesAxis.setTickLabelFont(getLineTickFont());
        }
        final int level = getRuntime().getProcessingContext().getCompatibilityLevel();
        if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8))
        {
          final double lineRangeMinimumVal = lineRangeMinimum == null ? 0 : lineRangeMinimum;
          final double lineRangeMaximumVal = lineRangeMaximum == null ? 0 : lineRangeMaximum;
          if (lineRangeMinimum != null)
          {
            linesAxis.setLowerBound(getLineRangeMinimum());
          }
          if (lineRangeMaximum != null)
          {
            linesAxis.setUpperBound(getRangeMaximum());
          }
          if (lineRangeMinimumVal == 0 && lineRangeMaximumVal == 1)
          {
            linesAxis.setLowerBound(0);
            linesAxis.setUpperBound(1);
            linesAxis.setAutoRange(true);
          }
        }
        else
        {
          if (lineRangeMinimum != null)
          {
            linesAxis.setLowerBound(lineRangeMinimum);
          }
          if (lineRangeMaximum != null)
          {
            linesAxis.setUpperBound(lineRangeMaximum);
          }
          linesAxis.setAutoRange(isLineAxisAutoRange());
        }
      }
    }

    final XYLineAndShapeRenderer linesRenderer = (XYLineAndShapeRenderer) plot.getRenderer(1);
    if (linesRenderer != null)
    {
      //set stroke with line width
      linesRenderer.setStroke(translateLineStyle(getLineWidth(), getLineStyle()));
      //hide shapes on line
View Full Code Here

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

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips)
    {
      toolTipGenerator
          = StandardXYToolTipGenerator.getTimeSeriesInstance();
    }

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

    final XYAreaRenderer2 renderer;
    if (stacked)
    {
      renderer = new StackedXYAreaRenderer2();
    }
    else
    {
      renderer = new XYAreaRenderer2();
    }
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setURLGenerator(urlGenerator);
    plot.setRenderer(renderer);

    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
  }
View Full Code Here

    {
      urlGenerator = new StandardXYURLGenerator();
    }
    final StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(toolTipGenerator, urlGenerator);
    renderer.setOutline(true);
    final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);

    plot.setRangeAxis(yAxis)// forces recalculation of the axis range

    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
  }
View Full Code Here

    if (xyDataset instanceof TimeSeriesCollection)
    {
      chart =
          ChartFactory.createTimeSeriesChart(computeTitle(), getDomainTitle(), getRangeTitle(), xyDataset,
              isShowLegend(), false, false);
      final XYPlot xyPlot = chart.getXYPlot();
      final XYLineAndShapeRenderer itemRenderer = (XYLineAndShapeRenderer) xyPlot.getRenderer();
      final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);
      renderer.setBaseToolTipGenerator(itemRenderer.getBaseToolTipGenerator());
      renderer.setURLGenerator(itemRenderer.getURLGenerator());
      xyPlot.setRenderer(renderer);

    }
    else
    {
      final PlotOrientation orientation = computePlotOrientation();
View Full Code Here

  protected void configureChart(final JFreeChart chart)
  {
    super.configureChart(chart);

    final XYPlot xypl = chart.getXYPlot();
    final XYItemRenderer renderer = xypl.getRenderer();
    if (renderer instanceof XYDotRenderer)
    {
      final XYDotRenderer renderer1 = (XYDotRenderer) renderer;
      renderer1.setDotHeight(getDotHeight());
      renderer1.setDotWidth(getDotWidth());
View Full Code Here

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

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips)
    {
      toolTipGenerator
          = StandardXYToolTipGenerator.getTimeSeriesInstance();
    }

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

    final XYBarRenderer renderer;
    if (stacked)
    {
      renderer = new StackedXYBarRenderer();
    }
    else
    {
      renderer = new XYBarRenderer();
    }
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setURLGenerator(urlGenerator);
    plot.setRenderer(renderer);

    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
  }
View Full Code Here

TOP

Related Classes of org.jfree.chart.plot.XYPlot

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.