Пример #1
0
  /** Confirm that the equals method can distinguish all the required fields. */
  public void testEquals() {

    NumberAxis a1 = new NumberAxis("Test");
    NumberAxis a2 = new NumberAxis("Test");
    assertTrue(a1.equals(a2));

    // private boolean autoRangeIncludesZero;
    a1.setAutoRangeIncludesZero(false);
    assertFalse(a1.equals(a2));
    a2.setAutoRangeIncludesZero(false);
    assertTrue(a1.equals(a2));

    // private boolean autoRangeStickyZero;
    a1.setAutoRangeStickyZero(false);
    assertFalse(a1.equals(a2));
    a2.setAutoRangeStickyZero(false);
    assertTrue(a1.equals(a2));

    // private NumberTickUnit tickUnit;
    a1.setTickUnit(new NumberTickUnit(25.0));
    assertFalse(a1.equals(a2));
    a2.setTickUnit(new NumberTickUnit(25.0));
    assertTrue(a1.equals(a2));

    // private NumberFormat numberFormatOverride;
    a1.setNumberFormatOverride(new DecimalFormat("0.00"));
    assertFalse(a1.equals(a2));
    a2.setNumberFormatOverride(new DecimalFormat("0.00"));
    assertTrue(a1.equals(a2));
  }
Пример #2
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;
  }
 private static JFreeChart createChart() {
   XYDataset xydataset = createDirectionDataset(600);
   JFreeChart jfreechart =
       ChartFactory.createTimeSeriesChart(
           "Time", "Date", "Direction", xydataset, true, true, false);
   XYPlot xyplot = (XYPlot) jfreechart.getPlot();
   xyplot.getDomainAxis().setLowerMargin(0.0D);
   xyplot.getDomainAxis().setUpperMargin(0.0D);
   NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
   numberaxis.setAutoRangeIncludesZero(false);
   TickUnits tickunits = new TickUnits();
   tickunits.add(new NumberTickUnit(180D, new CompassFormat()));
   tickunits.add(new NumberTickUnit(90D, new CompassFormat()));
   tickunits.add(new NumberTickUnit(45D, new CompassFormat()));
   tickunits.add(new NumberTickUnit(22.5D, new CompassFormat()));
   numberaxis.setStandardTickUnits(tickunits);
   xyplot.setRangeAxis(numberaxis);
   XYAreaRenderer xyarearenderer = new XYAreaRenderer();
   NumberAxis numberaxis1 = new NumberAxis("Force");
   numberaxis1.setRange(0.0D, 12D);
   xyarearenderer.setSeriesPaint(0, new Color(0, 0, 255, 128));
   xyplot.setDataset(1, createForceDataset(600));
   xyplot.setRenderer(1, xyarearenderer);
   xyplot.setRangeAxis(1, numberaxis1);
   xyplot.mapDatasetToRangeAxis(1, 1);
   return jfreechart;
 }
 private static JFreeChart createChart(CategoryDataset categorydataset) {
   JFreeChart jfreechart =
       ChartFactory.createLineChart(
           "Statistical Line Chart Demo 1",
           "Type",
           "Value",
           categorydataset,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   jfreechart.setBackgroundPaint(Color.white);
   CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
   categoryplot.setBackgroundPaint(Color.lightGray);
   categoryplot.setRangeGridlinePaint(Color.white);
   CategoryAxis categoryaxis = categoryplot.getDomainAxis();
   categoryaxis.setUpperMargin(0.0D);
   categoryaxis.setLowerMargin(0.0D);
   NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
   numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   numberaxis.setAutoRangeIncludesZero(true);
   StatisticalLineAndShapeRenderer statisticallineandshaperenderer =
       new StatisticalLineAndShapeRenderer(true, false);
   statisticallineandshaperenderer.setUseSeriesOffset(true);
   categoryplot.setRenderer(statisticallineandshaperenderer);
   return jfreechart;
 }
  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;
  }
Пример #6
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;
  }
  /**
   * Initializes the upper plot.
   *
   * @return An instance of {@link XYPlot}.
   */
  private XYPlot initializeUpperPlot() {
    loadedClasses = new YIntervalSeriesImproved("loaded classes");
    totalLoadedClasses = new YIntervalSeriesImproved("total loaded classes");

    YIntervalSeriesCollection yintervalseriescollection = new YIntervalSeriesCollection();
    yintervalseriescollection.addSeries(loadedClasses);
    yintervalseriescollection.addSeries(totalLoadedClasses);

    DeviationRenderer renderer = new DeviationRenderer(true, false);
    renderer.setBaseShapesVisible(true);
    renderer.setSeriesStroke(
        0, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    renderer.setSeriesFillPaint(0, new Color(255, 200, 200));
    renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
    renderer.setSeriesShape(0, new Ellipse2D.Double(-2.5, -2.5, 5.0, 5.0));
    renderer.setBaseToolTipGenerator(
        new StandardXYToolTipGenerator(
            StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
            DateFormat.getDateTimeInstance(),
            NumberFormat.getNumberInstance()));

    final NumberAxis rangeAxis = new NumberAxis("Classes");
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeMinimumSize(2000.0d);
    rangeAxis.setRangeType(RangeType.POSITIVE);
    rangeAxis.setAutoRangeIncludesZero(true);

    final XYPlot subplot = new XYPlot(yintervalseriescollection, null, rangeAxis, renderer);
    subplot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    subplot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    subplot.setRangeCrosshairVisible(true);

    return subplot;
  }
Пример #8
0
  private static JFreeChart createChart(XYDataset dataset, String exp) {
    JFreeChart chart =
        ChartFactory.createXYLineChart(
            "", "", "", dataset, PlotOrientation.VERTICAL, false, false, false);
    chart.setBorderVisible(false);
    chart.setAntiAlias(true);
    chart.setBackgroundPaint(Color.getHSBColor((float) 0, (float) 0, (float) 0.96));
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);

    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.WHITE); // 网格线颜色
    plot.setNoDataMessage("No data!");
    plot.setOutlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);

    plot.setBackgroundPaint(Color.getHSBColor((float) 0, (float) 0.01, (float) 0.91));

    // xylineandshaperenderer.setShapesFilled(true);
    NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRange(true);
    axis.setPositiveArrowVisible(true);
    axis.setAutoRangeIncludesZero(true);
    axis.setAutoRangeStickyZero(true);

    // List axisIndices = Arrays.asList(new Integer[] {new Integer(0),
    //        new Integer(1)});
    // plot.mapDatasetToDomainAxes(0, axisIndices);
    // plot.mapDatasetToRangeAxes(0, axisIndices);
    // ChartUtilities.applyCurrentTheme(chart);
    return chart;
  }
 @Override
 protected void afterPlot(List<? super InstanceStatistics> list, JFreeChart chart, XYPlot plot) {
   NumberAxis sizeAxis = (NumberAxis) plot.getRangeAxis(0);
   Font labelFont = sizeAxis.getLabelFont();
   Paint labelPaint = sizeAxis.getLabelPaint();
   TimeSeries tm = new TimeSeries("memory");
   for (int i = 0; i < list.size(); i++) {
     double memory = 0;
     MapStatistics mapStatistics = (MapStatistics) list.get(i);
     for (MapStatistics.LocalMapStatistics localMapStatistics :
         mapStatistics.getListOfLocalStats()) {
       memory =
           memory
               + localMapStatistics.ownedEntryMemoryCost
               + localMapStatistics.backupEntryMemoryCost
               + localMapStatistics.markedAsRemovedMemoryCost;
     }
     double mem = new Double(memory / (double) (1024 * 1024));
     tm.addOrUpdate(new Second(((MapStatistics) list.get(i)).getCreatedDate()), mem);
   }
   NumberAxis memoryAxis = new NumberAxis("memory (MB)");
   memoryAxis.setAutoRange(true);
   memoryAxis.setAutoRangeIncludesZero(false);
   plot.setDataset(1, new TimeSeriesCollection(tm));
   plot.setRangeAxis(1, memoryAxis);
   plot.mapDatasetToRangeAxis(1, 1);
   plot.setRenderer(1, new StandardXYItemRenderer());
   plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
   increaseRange(memoryAxis);
   memoryAxis.setLabelFont(labelFont);
   memoryAxis.setLabelPaint(labelPaint);
 }
Пример #10
0
 private XYPlot getLinePlot() throws KeyedException {
   // use a number axis on the left side (default)
   NumberAxis axis = new NumberAxis();
   axis.setAutoRangeIncludesZero(false);
   XYPlot plot = new XYPlot(null, null, axis, null);
   return plot;
 }
Пример #11
0
  public JPanel createChart(
      Date from,
      Date to,
      StockInfo stock1,
      StockInfo stock2,
      Color color1,
      Color color2,
      StockPriceType priceType) {

    LOG.info(
        "Generating chart for tickers:"
            + stock1.getTickerSymbol()
            + " & "
            + stock2.getTickerSymbol());

    String chartTitle = df.format(from) + " to " + df.format(to) + " " + priceType;
    XYDataset dataset1 = createDataset(stock1, priceType);
    XYDataset dataset2 = createDataset(stock2, priceType);

    JFreeChart chart =
        ChartFactory.createTimeSeriesChart(
            chartTitle,
            DOMAIN_AXIS_TITLE,
            stock1.getTickerSymbol() + RANGE_AXIS_SUFFIX,
            dataset1,
            true,
            true,
            false);

    XYPlot plot = chart.getXYPlot();
    NumberAxis axis2 = new NumberAxis(stock2.getTickerSymbol() + RANGE_AXIS_SUFFIX);
    Font tickLabelFont = axis2.getTickLabelFont().deriveFont(11.0F);
    Font labelFont = axis2.getLabelFont().deriveFont(15.0F).deriveFont(Font.BOLD);
    axis2.setTickLabelFont(tickLabelFont);
    axis2.setLabelFont(labelFont);
    axis2.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);

    StandardXYItemRenderer renderer = new StandardXYItemRenderer();
    renderer.setSeriesPaint(0, color1);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    plot.setRenderer(renderer);

    StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, color2);
    renderer2.setBaseShapesVisible(true);
    renderer2.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    plot.setRenderer(1, renderer2);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(df);

    ChartPanel chartPanel = new ChartPanel(chart);

    return chartPanel;
  }
  /**
   * 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);
  }
Пример #13
0
 private XYPlot getBarPlot() throws KeyedException {
   // use a number axis on the right side with a special formatter for millions
   NumberAxis axis = new NumberAxis();
   axis.setAutoRangeIncludesZero(false);
   axis.setNumberFormatOverride(new NumberFormatForMillions());
   XYPlot plot = new XYPlot(null, null, axis, null);
   plot.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
   return plot;
 }
Пример #14
0
  /**
   * A check for the interaction between the 'autoRangeIncludesZero' flag and the base setting in
   * the BarRenderer.
   */
  @Test
  public void testAutoRange4() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(100.0, "Row 1", "Column 1");
    dataset.setValue(200.0, "Row 1", "Column 2");
    JFreeChart chart =
        ChartFactory.createBarChart(
            "Test", "Categories", "Value", dataset, PlotOrientation.VERTICAL, false, false, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRangeIncludesZero(false);
    BarRenderer br = (BarRenderer) plot.getRenderer();
    br.setIncludeBaseInRange(false);
    assertEquals(95.0, axis.getLowerBound(), EPSILON);
    assertEquals(205.0, axis.getUpperBound(), EPSILON);

    br.setIncludeBaseInRange(true);
    assertEquals(0.0, axis.getLowerBound(), EPSILON);
    assertEquals(210.0, axis.getUpperBound(), EPSILON);

    axis.setAutoRangeIncludesZero(true);
    assertEquals(0.0, axis.getLowerBound(), EPSILON);
    assertEquals(210.0, axis.getUpperBound(), EPSILON);

    br.setIncludeBaseInRange(true);
    assertEquals(0.0, axis.getLowerBound(), EPSILON);
    assertEquals(210.0, axis.getUpperBound(), EPSILON);

    // now replacing the dataset should update the axis range...
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(900.0, "Row 1", "Column 1");
    dataset2.setValue(1000.0, "Row 1", "Column 2");
    plot.setDataset(dataset2);
    assertEquals(0.0, axis.getLowerBound(), EPSILON);
    assertEquals(1050.0, axis.getUpperBound(), EPSILON);

    br.setIncludeBaseInRange(false);
    assertEquals(0.0, axis.getLowerBound(), EPSILON);
    assertEquals(1050.0, axis.getUpperBound(), EPSILON);

    axis.setAutoRangeIncludesZero(false);
    assertEquals(895.0, axis.getLowerBound(), EPSILON);
    assertEquals(1005.0, axis.getUpperBound(), EPSILON);
  }
 private XYPlot createPlot(BenchmarkReport benchmarkReport, int scoreLevelIndex) {
   Locale locale = benchmarkReport.getLocale();
   NumberAxis xAxis = new NumberAxis("Time spent");
   xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale));
   NumberAxis yAxis = new NumberAxis("Constraint match total weight level " + scoreLevelIndex);
   yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
   yAxis.setAutoRangeIncludesZero(false);
   XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
   plot.setOrientation(PlotOrientation.VERTICAL);
   return plot;
 }
Пример #16
0
  private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart =
        ChartFactory.createLineChart(
            "Daily Stock Report", // chart title
            "Type", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
            );
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    // customise the range axis...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);
    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesStroke(
        0,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {10.0f, 6.0f},
            0.0f));
    renderer.setSeriesStroke(
        1,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {6.0f, 6.0f},
            0.0f));
    renderer.setSeriesStroke(
        2,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {2.0f, 6.0f},
            0.0f));
    return chart;
  }
Пример #17
0
  public JFreeChart createChart(int size) {
    CategoryDataset paramCategoryDataset = createDataset(size);
    // 创建主题样式
    StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
    // 设置标题字体
    standardChartTheme.setExtraLargeFont(new Font("隶书", Font.BOLD, 20));
    // 设置图例的字体
    standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 12));
    // 设置轴向的字体
    standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 12));
    // 应用主题样式
    ChartFactory.setChartTheme(standardChartTheme);
    JFreeChart localJFreeChart =
        ChartFactory.createLineChart(
            title, "期号", yTitle, paramCategoryDataset, PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot localCategoryPlot = (CategoryPlot) localJFreeChart.getPlot();
    //		SymbolAxis localSymbolAxis = new SymbolAxis("个数", new String[] {
    //				"0", "1", "2", "3", "4", "5", "6" });
    //		localCategoryPlot.setRangeAxis(localSymbolAxis);
    ChartUtilities.applyCurrentTheme(localJFreeChart);
    LineAndShapeRenderer xyitem = (LineAndShapeRenderer) localCategoryPlot.getRenderer();
    CategoryPlot plot = (CategoryPlot) localJFreeChart.getPlot();
    // 设置网格背景颜色
    plot.setBackgroundPaint(Color.white);
    // 设置网格竖线颜色
    plot.setDomainGridlinePaint(Color.black);
    // 设置网格横线颜色
    plot.setRangeGridlinePaint(Color.black);
    // 设置曲线图与xy轴的距离
    plot.setAxisOffset(new RectangleInsets(0D, 0D, 0D, 0D));

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);
    if ("和值".equals(type)) {
      rangeAxis.setLowerBound(70);
      rangeAxis.setTickUnit(new NumberTickUnit(10));
    } else {
      rangeAxis.setLowerBound(0);
      rangeAxis.setTickUnit(new NumberTickUnit(1));
    }
    //		rangeAxis.setUpperMargin(0.20);
    // 设置曲线显示各数据点的值
    xyitem.setBaseItemLabelsVisible(true);
    xyitem.setBasePositiveItemLabelPosition(
        new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
    xyitem.setSeriesStroke(0, new BasicStroke(1.5F));
    xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 14));
    xyitem.setSeriesShapesVisible(0, true);
    plot.setRenderer(xyitem);
    return localJFreeChart;
  }
Пример #18
0
 /**
  * A simple test for the auto-range calculation looking at a NumberAxis used as the range axis for
  * a CategoryPlot. In this case, the 'autoRangeIncludesZero' flag is set to false.
  */
 public void testAutoRange2() {
   DefaultCategoryDataset dataset = new DefaultCategoryDataset();
   dataset.setValue(100.0, "Row 1", "Column 1");
   dataset.setValue(200.0, "Row 1", "Column 2");
   JFreeChart chart =
       ChartFactory.createBarChart(
           "Test", "Categories", "Value", dataset, PlotOrientation.VERTICAL, false, false, false);
   CategoryPlot plot = (CategoryPlot) chart.getPlot();
   NumberAxis axis = (NumberAxis) plot.getRangeAxis();
   axis.setAutoRangeIncludesZero(false);
   assertEquals(axis.getLowerBound(), 95.0, EPSILON);
   assertEquals(axis.getUpperBound(), 205.0, EPSILON);
 }
Пример #19
0
  /**
   * temporal helper function
   *
   * @param dataset
   * @return
   */
  private JFreeChart createChart(TimeSeriesCollection dataset) {

    NumberAxis axis = new NumberAxis(null);
    axis.setAutoRangeIncludesZero(false);

    // parent=new CombinedRangeXYPlot(axis);

    // chart = null;

    // XYPlot plot2=new XYPlot(dataset2, new DateAxis(null), null, new StandardXYItemRenderer());
    // XYPlot subplot2=new XYPldt(dataset2, new DateAxis("Date 2"), null, )

    // parent.add(subplot1);
    // parent.add(subplot2);

    // chart=new JFreeChart(null, null, parent, false);

    chart = ChartFactory.createTimeSeriesChart(null, "", "", dataset, false, false, false);

    XYPlot plot1 = chart.getXYPlot();

    plot1.setDataset(dataset);
    plot1.setRenderer(new StandardXYItemRenderer());

    plot1.setSecondaryDataset(0, hld);
    CandlestickRenderer c1 = new CandlestickRenderer();

    // c1.setAutoWidthFactor(1.0);
    // c1.setAutoWidthGap(0.1);
    c1.setBasePaint(new Color(255, 255, 255));
    c1.setBaseOutlinePaint(new Color(255, 255, 255));

    c1.setPaint(new Color(255, 255, 255));

    c1.setUpPaint(new Color(255, 0, 0, 80));
    c1.setDownPaint(new Color(0, 255, 0, 80));

    plot1.setSecondaryRenderer(0, c1);

    // plot1.setSecondaryDataset(0, dataset2);

    XYDotRenderer xd1 = new XYDotRenderer();
    // plot1.setSecondaryRenderer(0, new AreaXYRenderer(AreaXYRenderer.AREA_AND_SHAPES));
    // plot1.setSecondaryRenderer(0, xd1);

    // chart=new JFreeChart("", null, plot1, false);

    chart.setBackgroundPaint(new Color(0, 0, 0));

    return chart;
  }
Пример #20
0
  private void writeSubSingleBenchmarkScoreCharts() {
    subSingleBenchmarkAggregationChartFileMap = new HashMap<ProblemBenchmarkResult, List<File>>();
    CategoryAxis xAxis = new CategoryAxis("Solver Configurations");
    NumberAxis yAxis = new NumberAxis("Scores distribution of single benchmark runs");
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setAutoRangeIncludesZero(false);
    BoxAndWhiskerRenderer renderer =
        new BoxAndWhiskerRenderer() {
          @Override
          public int
              getRowCount() { // TODO: HACK for https://issues.jboss.org/browse/PLANNER-429 center
                              // plotted boxes to x axis labels
            return 1;
          }
        };
    renderer.setFillBox(true);
    renderer.setUseOutlinePaintForWhiskers(true);
    renderer.setMedianVisible(true);
    renderer.setMeanVisible(false);
    renderer.setItemMargin(0.0);

    for (ProblemBenchmarkResult problemBenchmarkResult :
        plannerBenchmarkResult.getUnifiedProblemBenchmarkResultList()) {
      List<? extends BoxAndWhiskerCategoryDataset> datasetList =
          generateSubSingleBenchmarkScoreSummary(problemBenchmarkResult);
      List<File> chartFileList = new ArrayList<File>(datasetList.size());
      int scoreLevelIndex = 0;
      for (BoxAndWhiskerCategoryDataset dataset : datasetList) {
        CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
        JFreeChart chart =
            new JFreeChart(
                problemBenchmarkResult
                    + " (level "
                    + scoreLevelIndex
                    + ") single benchmark runs score distribution",
                JFreeChart.DEFAULT_TITLE_FONT,
                plot,
                true);
        chartFileList.add(
            writeChartToImageFile(
                chart,
                "SubSingleSummary"
                    + problemBenchmarkResult.getAnchorId()
                    + "Level"
                    + scoreLevelIndex));
        scoreLevelIndex++;
      }
      subSingleBenchmarkAggregationChartFileMap.put(problemBenchmarkResult, chartFileList);
    }
  }
Пример #21
0
  /**
   * Creates a new demo.
   *
   * @param title the frame title.
   */
  public RoundNumberGlobal(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    // final NumberAxis yAxis = new NumberAxis("Round number");
    final NumberAxis yAxis = new NumberAxis("");
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 16);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart =
        new JFreeChart(
            "Round Number" + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);

    TextTitle legendText = null;
    if (pf.size() == 1) {
      legendText = new TextTitle("Population Size");
    } else {
      legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
      output = new FileOutputStream("roundGlobalNumber" + pf + ".jpg");
      ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null);
    } catch (FileNotFoundException ex) {
      Logger.getLogger(RoundNumberGlobal.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
      Logger.getLogger(RoundNumberGlobal.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Пример #22
0
    /**
     * Creates a chart based on the first dataset, with a fitted linear regression line.
     *
     * @return the chart panel.
     */
    private ChartPanel createChartPanel1() {

      // create plot...
      NumberAxis xAxis = new NumberAxis("X");
      xAxis.setAutoRangeIncludesZero(false);
      NumberAxis yAxis = new NumberAxis("Y");
      yAxis.setAutoRangeIncludesZero(false);

      XYSplineRenderer renderer1 = new XYSplineRenderer();
      XYPlot plot = new XYPlot(this.data1, xAxis, yAxis, renderer1);
      plot.setBackgroundPaint(Color.lightGray);
      plot.setDomainGridlinePaint(Color.white);
      plot.setRangeGridlinePaint(Color.white);
      plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4));

      // create and return the chart panel...
      JFreeChart chart =
          new JFreeChart("XYSplineRenderer", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
      addChart(chart);
      ChartUtilities.applyCurrentTheme(chart);
      ChartPanel chartPanel = new ChartPanel(chart);
      return chartPanel;
    }
Пример #23
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));
    }
Пример #24
0
 /** Checks that the auto-range for the range axis on an XYPlot is working as expected. */
 @Test
 public void testXYAutoRange2() {
   XYSeries series = new XYSeries("Series 1");
   series.add(1.0, 1.0);
   series.add(2.0, 2.0);
   series.add(3.0, 3.0);
   XYSeriesCollection dataset = new XYSeriesCollection();
   dataset.addSeries(series);
   JFreeChart chart = ChartFactory.createScatterPlot("Test", "X", "Y", dataset);
   XYPlot plot = (XYPlot) chart.getPlot();
   NumberAxis axis = (NumberAxis) plot.getRangeAxis();
   axis.setAutoRangeIncludesZero(false);
   assertEquals(0.9, axis.getLowerBound(), EPSILON);
   assertEquals(3.1, axis.getUpperBound(), EPSILON);
 }
Пример #25
0
  /**
   * Constructs a horizontal colorbar axis, using default values where necessary.
   *
   * @param label the axis label.
   */
  public ColorBar(String label) {

    NumberAxis a = new NumberAxis(label);
    a.setAutoRangeIncludesZero(false);
    this.axis = a;
    this.axis.setLowerMargin(0.0);
    this.axis.setUpperMargin(0.0);

    this.colorPalette = new RainbowPalette();
    this.colorBarThickness = DEFAULT_COLORBAR_THICKNESS;
    this.colorBarThicknessPercent = DEFAULT_COLORBAR_THICKNESS_PERCENT;
    this.outerGap = DEFAULT_OUTERGAP;
    this.colorPalette.setMinZ(this.axis.getRange().getLowerBound());
    this.colorPalette.setMaxZ(this.axis.getRange().getUpperBound());
  }
Пример #26
0
  /**
   * A demonstration application showing a scatter plot.
   *
   * @param title the frame title.
   */
  public ScatterPlotDemo4(String title) {

    super(title);
    XYSeries series = new XYSeries("Average Weight");
    series.add(-20.0, 20.0);
    series.add(40.0, 25.0);
    series.add(55.0, 50.0);
    series.add(70.0, 65.0);
    series.add(270.0, 65.0);
    series.add(570.0, 55.0);
    XYDataset data = new XYSeriesCollection(series);
    JFreeChart chart =
        ChartFactory.createScatterPlot(
            "Scatter Plot Demo", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = chart.getXYPlot();
    LogElemRenderer render = new LogElemRenderer();
    render.setDotWidth(25);
    render.setDotHeight(25);
    plot.setRenderer(render);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(800, 470));

    Border border =
        BorderFactory.createCompoundBorder(
            BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createEtchedBorder());
    chartPanel.setBorder(border);
    add(chartPanel);

    JPanel dashboard = new JPanel(new BorderLayout());
    dashboard.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4));
    // make the slider units "minutes"
    slider = new JSlider(-200, 200, 0);
    slider.setPaintLabels(true);
    slider.setMajorTickSpacing(50);
    slider.setPaintTicks(true);
    slider.addChangeListener(this);
    dashboard.add(slider);
    add(dashboard, BorderLayout.SOUTH);

    // setContentPane(chartPanel);

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

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

      JButton jbutton = new JButton("ALL");
      jbutton.setActionCommand("ADD_ALL");
      jbutton.addActionListener(this);
      jpanel.add(jbutton);
      add(jpanel, "South");
      chartpanel.setPreferredSize(new Dimension(500, 470));
      chartpanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    }
Пример #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;
  }
Пример #29
0
  public void addSeries(String yaxisName, TimeSeries series) {
    NumberAxis axis2 = new NumberAxis(yaxisName);
    axis2.setFixedDimension(10.0);
    axis2.setAutoRangeIncludesZero(false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeAxis(axisNum, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);

    plot.setDataset(axisNum, dataset);
    plot.mapDatasetToRangeAxis(axisNum, axisNum);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    plot.setRenderer(axisNum, renderer2);

    axisNum++;
  }
Пример #30
0
 /* (non-Javadoc)
  * @see com.feilong.tools.jfreechart.xy.FeiLongBaseXYChartEntity#setChildDefaultNumberAxisAttributes()
  */
 protected void setChildDefaultNumberAxisAttributes() {
   CategoryDataset categoryDataset = categoryPlot.getDataset();
   // 数据轴的数据标签 可以只显示整数标签,需要将AutoTickUnitSelection设false
   // numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   double fudong = 0.5;
   NumberAxis numberAxis = getNumberAxis();
   // 设置最大值
   numberAxis.setUpperBound(
       DatasetUtilities.findMaximumRangeValue(categoryDataset).doubleValue() + fudong);
   // 设置最小值
   numberAxis.setLowerBound(
       DatasetUtilities.findMinimumRangeValue(categoryDataset).doubleValue() - fudong);
   // 设置坐标轴的最小值,默认的是0.00000001
   // numberAxis.setAutoRangeMinimumSize(1);
   // 是否强制在自动选择的数据范围中包含0
   numberAxis.setAutoRangeIncludesZero(false);
   // 纵轴显示范围
   // numberAxis.setRange(85, 100.5);
 }