Exemplo n.º 1
0
  /**
   * Creates a line chart with default settings.
   *
   * @param title the chart title.
   * @param categoryAxisLabel the label for the category axis.
   * @param valueAxisLabel the 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 line chart.
   */
  public static JFreeChart createLineChart(
      String title,
      java.awt.Font titleFont,
      String categoryAxisLabel,
      String valueAxisLabel,
      CategoryDataset data,
      PlotOrientation orientation,
      boolean legend,
      boolean tooltips,
      boolean urls,
      CategoryURLGenerator urlGenerator) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    LineAndShapeRenderer renderer = new LineAndShapeRenderer();
    renderer.setLinesVisible(true);
    renderer.setShapesVisible(false);
    if (tooltips) {
      renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
      renderer.setItemURLGenerator(urlGenerator);
    }
    CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart(title, titleFont, plot, legend);

    return chart;
  }
  /**
   * Creates a chart.
   *
   * @return A chart.
   */
  private static JFreeChart createChart() {

    CategoryDataset dataset1 = createDataset1();
    NumberAxis rangeAxis1 = new NumberAxis("Value");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
    renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1);
    subplot1.setDomainGridlinesVisible(true);

    CategoryDataset dataset2 = createDataset2();
    NumberAxis rangeAxis2 = new NumberAxis("Value");
    rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer2 = new BarRenderer();
    renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2);
    subplot2.setDomainGridlinesVisible(true);

    CategoryAxis domainAxis = new CategoryAxis("Category");
    CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
    plot.add(subplot1, 2);
    plot.add(subplot2, 1);

    JFreeChart chart =
        new JFreeChart(
            "Combined Domain Category Plot Demo", new Font("SansSerif", Font.BOLD, 12), plot, true);
    ChartUtilities.applyCurrentTheme(chart);
    return chart;
  }
  /**
   * Creates a chart.
   *
   * @return A chart.
   */
  private static JFreeChart createChart(String symbol) {

    CategoryDataset dataset1 = createDataset1(symbol);
    NumberAxis rangeAxis1 = new NumberAxis("Jumlah");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
    renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1);
    subplot1.setDomainGridlinesVisible(true);

    CategoryDataset dataset2 = createDataset2(symbol);
    NumberAxis rangeAxis2 = new NumberAxis("Jumlah");
    rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer2 = new BarRenderer();
    renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2);
    subplot2.setDomainGridlinesVisible(true);

    CategoryAxis domainAxis = new CategoryAxis("Tahun Periksa");
    CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
    //             CombinedCategoryPlot plot = new CombinedCategoryPlot(
    //                     domainAxis, new NumberAxis("Range"));
    plot.add(subplot1, 2);
    plot.add(subplot2, 1);

    JFreeChart result = new JFreeChart("", new Font("SansSerif", Font.BOLD, 10), plot, true);
    return result;
  }
Exemplo n.º 4
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;
  }
Exemplo n.º 5
0
  @Override
  protected JFreeChart createGraph() {
    final JFreeChart chart =
        ChartFactory.createLineChart(
            null, // chart title
            null, // unused
            yLabel, // range axis label
            categoryDataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
            );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    final LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerBound(0);
    rangeAxis.setAutoRange(true);

    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseStroke(new BasicStroke(2.0f));
    ColorPalette.apply(renderer);

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0));

    return chart;
  }
Exemplo n.º 6
0
  public static void createChart() {
    // criação do gráfico
    JFreeChart chart =
        ChartFactory.createLineChart(
            "Gráfico da Função: " + funcao, // titulo do gráfico
            "Resultados", // eixoy
            "Valores de Entrada", // eixox
            dataset, // base de dados
            PlotOrientation.VERTICAL,
            false, // legenda
            true, // dica, popup
            false // urls
            );
    // personalizando o gráfico

    TextTitle source =
        new TextTitle(
            "Atenção! Dependo do número de valores, pode ser que não apareça os mesmos no eixo horizontal.");
    source.setFont(new Font("SansSerif", Font.PLAIN, 10));
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    source.setBackgroundPaint(Color.WHITE);

    chart.addSubtitle(source);
    chart.setBackgroundPaint(Color.GRAY);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.BLACK);

    // desenha os pontos
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setLegendTextPaint(1, Color.WHITE);

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

    ChartFrame frame = new ChartFrame("Gráfico - Calculadora Função Atividade 2", chart);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
Exemplo n.º 7
0
  private void initCharts() {
    dataset = new DefaultCategoryDataset();

    // XY:s
    NumberAxis rangeAxis1 = new NumberAxis("Values");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
    renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    trendPlot = new CategoryPlot(dataset, null, rangeAxis1, renderer1);
    trendPlot.setDomainGridlinesVisible(true);

    // Box:
    NumberAxis rangeAxis2 = new NumberAxis("Values");
    rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer2 = new BarRenderer();
    renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    sizePlot = new CategoryPlot(dataset, null, rangeAxis2, renderer2);
    sizePlot.setDomainGridlinesVisible(true);
  }
  private static void configureLineAndShapeRenderer(
      LineAndShapeRenderer renderer, ValueSource valueSource, PlotInstance plotInstance) {
    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    int seriesCount = valueSourceData.getSeriesCount();
    SeriesFormat seriesFormat = valueSource.getSeriesFormat();
    DimensionConfig domainConfig = valueSource.getDomainConfig();
    DimensionConfig colorDimensionConfig =
        plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.COLOR);
    DimensionConfig shapeDimensionConfig =
        plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.SHAPE);

    renderer.setDefaultEntityRadius(4);

    // loop all series and set series format
    for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
      // configure linestyle
      if (seriesFormat.getLineStyle() != LineStyle.NONE) {
        renderer.setSeriesLinesVisible(seriesIdx, true);
        renderer.setSeriesStroke(seriesIdx, seriesFormat.getStroke(), false);
      } else {
        renderer.setSeriesLinesVisible(seriesIdx, false);
      }

      // configure series shape if necessary
      if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) {
        if (seriesFormat.getItemShape() != ItemShape.NONE) {
          renderer.setSeriesShapesVisible(seriesIdx, true);
          renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape());
        } else {
          renderer.setSeriesShapesVisible(seriesIdx, false);
        }
      }

      // configure series color if necessary
      if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) {
        Color itemColor = seriesFormat.getItemColor();
        renderer.setSeriesPaint(seriesIdx, itemColor);
      }
      renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT);
      renderer.setUseOutlinePaint(true);
    }
  }
Exemplo n.º 9
0
  /** Creates a trend chart. */
  public JFreeChart createChart(CategoryDataset ds) {
    final JFreeChart chart =
        ChartFactory.createLineChart(
            null, // chart title
            null, // unused
            null, // range axis label
            ds, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
            );

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseStroke(new BasicStroke(3));
    configureRenderer(renderer);

    final CategoryAxis domainAxis = new NoOverlapCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

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

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    return chart;
  }
Exemplo n.º 10
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;
  }
Exemplo n.º 11
0
 protected void setDefaultCategoryItemRenderer() {
   // 获得renderer 注意这里是下嗍造型到lineandshaperenderer!!
   lineandshaperenderer = (LineAndShapeRenderer) categoryPlot.getRenderer();
   // 天蓝
   lineandshaperenderer.setSeriesPaint(0, new Color(41, 106, 232));
   // lineandshaperenderer.setSeriesPaint(1, new Color(255,0,255));//桃红2
   // lineandshaperenderer.setSeriesPaint(2, new Color(255,255,128));//黄色3
   // lineandshaperenderer.setSeriesPaint(3, new Color(0,255,255));//蓝4
   // lineandshaperenderer.setSeriesPaint(4, new Color(128,0,128));//紫5
   // lineandshaperenderer.setSeriesPaint(5, new Color(0,0,255));//墨绿6
   // lineandshaperenderer.setSeriesPaint(6, new Color(0,0,128));//蓝7
   // lineandshaperenderer.setSeriesPaint(7, new Color(0,204,255));//草绿
   // lineandshaperenderer.setSeriesPaint(8, new Color(192,192,192));//天蓝
   // lineandshaperenderer.setSeriesPaint(9, new Color(204,255,204));//天蓝
   // 点(即数据点)可见
   lineandshaperenderer.setBaseShapesVisible(true);
   // 显示折点数据
   lineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
   // 显示折点数据
   lineandshaperenderer.setBaseItemLabelsVisible(true);
   // 折点数据字体
   lineandshaperenderer.setBaseItemLabelFont(FontUtil.getFont_verdana_Plain(12));
   // 折点数据显示位置
   ItemLabelPosition position =
       new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER);
   lineandshaperenderer.setBasePositiveItemLabelPosition(position);
   // 点(即数据点)间有连线可见
   lineandshaperenderer.setBaseLinesVisible(true);
   // 定义series为”First”的(即series1)点之间的连线 ,这里是虚线,默认是直线
   // lineandshaperenderer.setSeriesStroke(0, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 10F,
   // 6F }, 0.0F));
   // XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
   // xylineandshaperenderer.setSeriesLinesVisible(0, false); //第一个XYSeries数据点间连线不可见
   // xylineandshaperenderer.setSeriesShapesVisible(1, false); //第二个XYSeries数据点不可见
   // xyplot.setRenderer(xylineandshaperenderer);
 }
Exemplo n.º 12
0
 protected void configureRenderer(LineAndShapeRenderer renderer) {
   renderer.setSeriesPaint(0, ColorPalette.BLUE); // online
   renderer.setSeriesPaint(1, ColorPalette.RED); // busy
   renderer.setSeriesPaint(2, ColorPalette.GREY); // queue
   renderer.setSeriesPaint(3, ColorPalette.YELLOW); // available
 }
  protected JPanel createPlotPanel(Plot plot) {
    this.plotInsets = plot.getInsets();
    this.backgroundPaintSample = new PaintSample(plot.getBackgroundPaint());
    this.outlineStrokeSample = new StrokeSample(plot.getOutlineStroke());
    this.outlinePaintSample = new PaintSample(plot.getOutlinePaint());
    if (plot instanceof CategoryPlot) {
      this.plotOrientation = ((CategoryPlot) plot).getOrientation();
    } else if (plot instanceof XYPlot) {
      this.plotOrientation = ((XYPlot) plot).getOrientation();
    }
    if (plot instanceof CategoryPlot) {
      CategoryItemRenderer renderer = ((CategoryPlot) plot).getRenderer();
      if (renderer instanceof LineAndShapeRenderer) {
        LineAndShapeRenderer r = (LineAndShapeRenderer) renderer;
        this.drawLines = BooleanUtilities.valueOf(r.getBaseLinesVisible());
        this.drawShapes = BooleanUtilities.valueOf(r.getBaseShapesVisible());
      }
    } else if (plot instanceof XYPlot) {
      XYItemRenderer renderer = ((XYPlot) plot).getRenderer();
      if (renderer instanceof StandardXYItemRenderer) {
        StandardXYItemRenderer r = (StandardXYItemRenderer) renderer;
        this.drawLines = BooleanUtilities.valueOf(r.getPlotLines());
        this.drawShapes = BooleanUtilities.valueOf(r.getBaseShapesVisible());
      }
    }

    setLayout(new BorderLayout());

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

    // create a panel for the settings...
    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createEtchedBorder(),
            plot.getPlotType() + localizationResources.getString(":")));

    JPanel general = new JPanel(new BorderLayout());
    general.setBorder(BorderFactory.createTitledBorder(localizationResources.getString("General")));

    JPanel interior = new JPanel(new LCBLayout(7));
    interior.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));

    //        interior.add(new JLabel(localizationResources.getString("Insets")));
    //        JButton button = new JButton(
    //            localizationResources.getString("Edit...")
    //        );
    //        button.setActionCommand("Insets");
    //        button.addActionListener(this);
    //
    //        this.insetsTextField = new InsetsTextField(this.plotInsets);
    //        this.insetsTextField.setEnabled(false);
    //        interior.add(this.insetsTextField);
    //        interior.add(button);

    interior.add(new JLabel(localizationResources.getString("Outline_stroke")));
    JButton button = new JButton(localizationResources.getString("Select..."));
    button.setActionCommand("OutlineStroke");
    button.addActionListener(this);
    interior.add(this.outlineStrokeSample);
    interior.add(button);

    interior.add(new JLabel(localizationResources.getString("Outline_Paint")));
    button = new JButton(localizationResources.getString("Select..."));
    button.setActionCommand("OutlinePaint");
    button.addActionListener(this);
    interior.add(this.outlinePaintSample);
    interior.add(button);

    interior.add(new JLabel(localizationResources.getString("Background_paint")));
    button = new JButton(localizationResources.getString("Select..."));
    button.setActionCommand("BackgroundPaint");
    button.addActionListener(this);
    interior.add(this.backgroundPaintSample);
    interior.add(button);

    if (this.plotOrientation != null) {
      boolean isVertical = this.plotOrientation.equals(PlotOrientation.VERTICAL);
      int index = isVertical ? ORIENTATION_VERTICAL : ORIENTATION_HORIZONTAL;
      interior.add(new JLabel(localizationResources.getString("Orientation")));
      this.orientationCombo = new JComboBox(orientationNames);
      this.orientationCombo.setSelectedIndex(index);
      this.orientationCombo.setActionCommand("Orientation");
      this.orientationCombo.addActionListener(this);
      interior.add(new JPanel());
      interior.add(this.orientationCombo);
    }

    if (this.drawLines != null) {
      interior.add(new JLabel(localizationResources.getString("Draw_lines")));
      this.drawLinesCheckBox = new JCheckBox();
      this.drawLinesCheckBox.setSelected(this.drawLines.booleanValue());
      this.drawLinesCheckBox.setActionCommand("DrawLines");
      this.drawLinesCheckBox.addActionListener(this);
      interior.add(new JPanel());
      interior.add(this.drawLinesCheckBox);
    }

    if (this.drawShapes != null) {
      interior.add(new JLabel(localizationResources.getString("Draw_shapes")));
      this.drawShapesCheckBox = new JCheckBox();
      this.drawShapesCheckBox.setSelected(this.drawShapes.booleanValue());
      this.drawShapesCheckBox.setActionCommand("DrawShapes");
      this.drawShapesCheckBox.addActionListener(this);
      interior.add(new JPanel());
      interior.add(this.drawShapesCheckBox);
    }

    general.add(interior, BorderLayout.NORTH);

    JPanel appearance = new JPanel(new BorderLayout());
    appearance.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    appearance.add(general, BorderLayout.NORTH);

    JTabbedPane tabs = createPlotTabs(plot);
    tabs.add(localizationResources.getString("Appearance"), appearance);
    panel.add(tabs);

    return panel;
  }
Exemplo n.º 14
0
  @Override
  public JFreeChart createChart(int nbr) {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    // DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();   bias

    for (Tuple<String, double[]> tuple : this.mreDblFileList) {
      for (int h = 0; h < 24; h++) {
        dataset0.addValue(tuple.getSecond()[h], tuple.getFirst(), Integer.toString(h + 1));
      }
    }

    this.chart_ =
        ChartFactory.createLineChart(
            "",
            "Hour",
            "Mean rel error [%]",
            dataset0,
            PlotOrientation.VERTICAL,
            true, // legend?
            true, // tooltips?
            false // URLs?
            );

    CategoryPlot plot = this.chart_.getCategoryPlot();
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    final LineAndShapeRenderer renderer = new LineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GREEN);
    renderer.setSeriesPaint(2, Color.BLUE);
    renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());
    plot.setRenderer(0, renderer);

    Color transparent = new Color(0, 0, 255, 0);
    this.chart_.setBackgroundPaint(
        transparent); // pink : Color.getHSBColor((float) 0.0, (float) 0.0, (float) 0.93)
    plot.setBackgroundPaint(Color.getHSBColor((float) 0.0, (float) 0.0, (float) 0.93));
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeGridlinesVisible(true);

    final CategoryAxis axisX = new CategoryAxis("Hour");
    axisX.setTickLabelFont(new Font("SansSerif", Font.BOLD, 15));
    plot.setDomainAxis(axisX);

    // final ValueAxis axis2 = new NumberAxis("Mean abs bias [agent/h]");
    // plot.setRangeAxis(1, axis2);

    final ValueAxis axisY = plot.getRangeAxis(0);
    axisY.setRange(0.0, 100.0);
    axisY.setTickLabelFont(new Font("SansSerif", Font.BOLD, 21));

    final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    renderer2.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());
    renderer2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator());
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);

    this.chart_.getLegend().setItemFont(new Font("SansSerif", Font.BOLD, 17));
    this.chart_.getLegend().setVisible(false);

    return this.chart_;
  }
  /**
   * Updates the plot properties to match the properties defined on the panel.
   *
   * @param plot The plot.
   */
  public void updatePlotProperties(Plot plot) {

    // set the plot properties...
    plot.setOutlinePaint(getOutlinePaint());
    plot.setOutlineStroke(getOutlineStroke());
    plot.setBackgroundPaint(getBackgroundPaint());
    plot.setInsets(getPlotInsets());

    // then the axis properties...
    if (this.domainAxisPropertyPanel != null) {
      Axis domainAxis = null;
      if (plot instanceof CategoryPlot) {
        CategoryPlot p = (CategoryPlot) plot;
        domainAxis = p.getDomainAxis();
      } else if (plot instanceof XYPlot) {
        XYPlot p = (XYPlot) plot;
        domainAxis = p.getDomainAxis();
      }
      if (domainAxis != null) {
        this.domainAxisPropertyPanel.setAxisProperties(domainAxis);
      }
    }

    if (this.rangeAxisPropertyPanel != null) {
      Axis rangeAxis = null;
      if (plot instanceof CategoryPlot) {
        CategoryPlot p = (CategoryPlot) plot;
        rangeAxis = p.getRangeAxis();
      } else if (plot instanceof XYPlot) {
        XYPlot p = (XYPlot) plot;
        rangeAxis = p.getRangeAxis();
      } else if (plot instanceof PolarPlot) {
        PolarPlot p = (PolarPlot) plot;
        rangeAxis = p.getAxis();
      }
      if (rangeAxis != null) {
        this.rangeAxisPropertyPanel.setAxisProperties(rangeAxis);
      }
    }

    if (this.plotOrientation != null) {
      if (plot instanceof CategoryPlot) {
        CategoryPlot p = (CategoryPlot) plot;
        p.setOrientation(this.plotOrientation);
      } else if (plot instanceof XYPlot) {
        XYPlot p = (XYPlot) plot;
        p.setOrientation(this.plotOrientation);
      }
    }

    if (this.drawLines != null) {
      if (plot instanceof CategoryPlot) {
        CategoryPlot p = (CategoryPlot) plot;
        CategoryItemRenderer r = p.getRenderer();
        if (r instanceof LineAndShapeRenderer) {
          ((LineAndShapeRenderer) r).setLinesVisible(this.drawLines.booleanValue());
        }
      } else if (plot instanceof XYPlot) {
        XYPlot p = (XYPlot) plot;
        XYItemRenderer r = p.getRenderer();
        if (r instanceof StandardXYItemRenderer) {
          ((StandardXYItemRenderer) r).setPlotLines(this.drawLines.booleanValue());
        }
      }
    }

    if (this.drawShapes != null) {
      if (plot instanceof CategoryPlot) {
        CategoryPlot p = (CategoryPlot) plot;
        CategoryItemRenderer r = p.getRenderer();
        if (r instanceof LineAndShapeRenderer) {
          ((LineAndShapeRenderer) r).setShapesVisible(this.drawShapes.booleanValue());
        }
      } else if (plot instanceof XYPlot) {
        XYPlot p = (XYPlot) plot;
        XYItemRenderer r = p.getRenderer();
        if (r instanceof StandardXYItemRenderer) {
          ((StandardXYItemRenderer) r).setBaseShapesVisible(this.drawShapes.booleanValue());
        }
      }
    }

    // dmo: added this panel for colorbar control. (start dmo additions)
    if (this.colorBarAxisPropertyPanel != null) {
      ColorBar colorBar = null;
      if (plot instanceof ContourPlot) {
        ContourPlot p = (ContourPlot) plot;
        colorBar = p.getColorBar();
      }
      if (colorBar != null) {
        this.colorBarAxisPropertyPanel.setAxisProperties(colorBar);
      }
    }
    // dmo: (end dmo additions)

  }
Exemplo n.º 16
0
    protected void configureRenderer(LineAndShapeRenderer renderer) {
      renderer.setBaseStroke(new BasicStroke(3));

      for (int i = 0; i < series.size(); i++) renderer.setSeriesPaint(i, series.get(i).color);
    }
Exemplo n.º 17
0
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return a chart.
   */
  private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart =
        ChartFactory.createLineChart(
            "Line Chart Demo 5", // chart title
            "Type", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
            );

    // final StandardLegend legend = (StandardLegend) chart.getLegend();
    // legend.setDisplaySeriesShapes(true);

    final Shape[] shapes = new Shape[3];
    int[] xpoints;
    int[] ypoints;

    // right-pointing triangle
    xpoints = new int[] {-3, 3, -3};
    ypoints = new int[] {-3, 0, 3};
    shapes[0] = new Polygon(xpoints, ypoints, 3);

    // vertical rectangle
    shapes[1] = new Rectangle2D.Double(-2, -3, 3, 6);

    // left-pointing triangle
    xpoints = new int[] {-3, 3, 3};
    ypoints = new int[] {0, -3, 3};
    shapes[2] = new Polygon(xpoints, ypoints, 3);

    final DrawingSupplier supplier =
        new DefaultDrawingSupplier(
            DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            shapes);
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setDrawingSupplier(supplier);

    chart.setBackgroundPaint(Color.yellow);

    // set the stroke for each series...
    plot.getRenderer()
        .setSeriesStroke(
            0,
            new BasicStroke(
                2.0f,
                BasicStroke.CAP_ROUND,
                BasicStroke.JOIN_ROUND,
                1.0f,
                new float[] {10.0f, 6.0f},
                0.0f));
    plot.getRenderer()
        .setSeriesStroke(
            1,
            new BasicStroke(
                2.0f,
                BasicStroke.CAP_ROUND,
                BasicStroke.JOIN_ROUND,
                1.0f,
                new float[] {6.0f, 6.0f},
                0.0f));
    plot.getRenderer()
        .setSeriesStroke(
            2,
            new BasicStroke(
                2.0f,
                BasicStroke.CAP_ROUND,
                BasicStroke.JOIN_ROUND,
                1.0f,
                new float[] {2.0f, 6.0f},
                0.0f));

    // customise the renderer...
    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    // renderer.setDrawShapes(true);
    renderer.setItemLabelsVisible(true);
    // renderer.setLabelGenerator(new StandardCategoryLabelGenerator());

    // customise the range axis...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setUpperMargin(0.12);

    return chart;
  }
Exemplo n.º 18
0
  public ChartPanel getChartPanel() {
    JFreeChart c = null;
    CombinedDomainCategoryPlot combinedP = null;

    for (final String valueProperty : valueP) {
      final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
      for (int i = 0; i < set.getNumResults(); i++)
        dataset.addValue(
            (Double) set.getResultValue(i, valueProperty),
            set.getResultValue(i, seriesP).toString(),
            set.getResultValue(i, categoryP).toString());
      JFreeChart chart =
          ChartFactory.createLineChart(
              title,
              xAxisLabel,
              ((yAxisLabel == null) ? set.getNiceProperty(valueProperty) : yAxisLabel)
                  + yAxisLabelSuffix,
              dataset,
              PlotOrientation.VERTICAL,
              showLegend,
              tooltips,
              false /*urls*/);

      chart.getPlot().setBackgroundPaint(Color.WHITE);
      ((CategoryPlot) chart.getPlot()).setRangeGridlinePaint(Color.GRAY);
      //			((CategoryPlot) chart.getPlot()).setDomainGridlinesVisible(true);
      //			((CategoryPlot) chart.getPlot()).setDomainGridlinePaint(Color.GRAY);
      chart.setBackgroundPaint(new Color(0, 0, 0, 0));
      CategoryPlot plot = (CategoryPlot) chart.getPlot();

      Color cols[];
      Shape shapes[] = null;
      if (dataset.getRowCount() == 2) {
        cols =
            new Color[] {
              ColorUtil.bright(FreeChartUtil.COLORS[0]), ColorUtil.dark(FreeChartUtil.COLORS[1])
            };
        shapes =
            new Shape[] {ShapeUtilities.createDiamond(4.5f), new Ellipse2D.Float(-3f, -3f, 6f, 6f)};
      } else if (dataset.getRowCount() == 3) {
        Color orange = new Color(244, 125, 43);
        // Color orange = new Color(255, 145, 63);
        Color red = new Color(238, 46, 47);
        Color blue = new Color(24, 90, 169);
        // Color blue = new Color(4, 70, 149);
        cols = new Color[] {red, orange, blue};

        //
        //				Color bright = Color.MAGENTA;
        //				Color medium = Color.RED;
        //				Color dark = new Color(0, 0, 75);
        //				cols = new Color[] { bright, medium, dark };
      } else cols = FreeChartUtil.COLORS;

      //			for (int i = 0; i < cols.length; i++)
      //			{
      //				cols[i] = ColorUtil.grayscale(cols[i]);
      //				int color = cols[i].getRGB();
      //				int red = (color >>> 16) & 0xFF;
      //				int green = (color >>> 8) & 0xFF;
      //				int blue = (color >>> 0) & 0xFF;
      //				float luminance = (red * 0.2126f + green * 0.7152f + blue * 0.0722f) / 255;
      //				System.out.println(luminance);
      //			}

      //			for (int i = 0; i < dataset.getColumnCount(); i++)
      //			{
      //				//							int seriesIdx = -1;
      //				//							for (int j = 0; j < dataset.getRowCount(); j++)
      //				//							{
      //				//								String seriesValue = dataset.getRowKey(j).toString();
      //				//								String categoryValue = dataset.getColumnKey(i).toString();
      //				//								if ((drawShape.containsKey(valueProperty) &&
      // seriesValue.equals(drawShape.get(valueProperty).get(
      //				//										categoryValue))))
      //				//								{
      //				//									seriesIdx = j;
      //				//									break;
      //				//								}
      //				//							}
      //				//
      //				//							if (seriesIdx != -1)
      //				//							{
      //				CategoryLineAnnotation anno = new CategoryLineAnnotation(dataset.getColumnKey(i),
      // dataset
      //						.getValue(0, i).doubleValue(), dataset.getColumnKey(i), dataset.getValue(1,
      // i).doubleValue(),
      //						ColorUtil.transparent(Color.GRAY, 200), new BasicStroke(1.0f, BasicStroke.CAP_ROUND,
      //								BasicStroke.JOIN_ROUND, 5.0f, new float[] { 2.0f, 2.0f }, 5.0f));
      //				int thick = 10;
      //				Color back = new Color(255, 255, 255);
      //
      //				//				CategoryLineAnnotation anno = new CategoryLineAnnotation(dataset.getColumnKey(i),
      // dataset
      //				//						.getValue(0, i).doubleValue(), dataset.getColumnKey(i), dataset.getValue(1,
      // i).doubleValue(),
      //				//						ColorUtil.transparent(back, 200), new BasicStroke(thick, BasicStroke.CAP_ROUND,
      //				//								BasicStroke.JOIN_ROUND));
      //				plot.addAnnotation(anno);
      //
      //				if (dataset.getValue(0, i).doubleValue() > dataset.getValue(1, i).doubleValue())
      //				{
      //					addAnnotation(plot, dataset, i, 1, cols, back, thick, true, valueProperty);
      //					addAnnotation(plot, dataset, i, 0, cols, back, thick, false, valueProperty);
      //				}
      //				else
      //				{
      //					addAnnotation(plot, dataset, i, 0, cols, back, thick, false, valueProperty);
      //					addAnnotation(plot, dataset, i, 1, cols, back, thick, true, valueProperty);
      //
      //				}
      //			}

      LineAndShapeRenderer renderer =
          new LineAndShapeRenderer() {
            @Override
            public boolean getItemShapeVisible(int series, int item) {
              //					//					return dataset.getValue(series, item).doubleValue() > dataset.getValue(1
              // - series, item)
              //					//							.doubleValue();
              //
              //					String seriesValue = dataset.getRowKey(series).toString();
              //					String categoryValue = dataset.getColumnKey(item).toString();
              //					return (drawShape.containsKey(valueProperty) &&
              // seriesValue.equals(drawShape.get(valueProperty)
              //							.get(categoryValue)));
              //					//					return new Random().nextBoolean();

              return false;
            }

            @Override
            public boolean getItemShapeFilled(int series, int item) {
              String seriesValue = dataset.getRowKey(series).toString();
              String categoryValue = dataset.getColumnKey(item).toString();
              return (drawShape.containsKey(valueProperty)
                  && seriesValue.equals(drawShape.get(valueProperty).get(categoryValue)));
            }

            @Override
            public Boolean getSeriesLinesVisible(int series) {
              return true;
            }
          };

      //			Polygon p1 = new Polygon();
      //			p1.addPoint(0, -9);
      //			p1.addPoint(-3, -5);
      //			p1.addPoint(3, -5);
      //			renderer.setBaseShape(p1);

      plot.setRenderer(renderer);
      //			LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
      //			renderer.set

      if (markers != null && markers.containsKey(valueProperty))
        for (String category : markers.keySet2(valueProperty)) {
          CategoryMarker marker = new CategoryMarker(category);
          marker.setOutlinePaint(null);
          marker.setPaint(new Color(150, 150, 150));
          marker.setDrawAsLine(true);
          marker.setLabel(" " + markers.get(valueProperty, category));

          //				marker.setLabelFont(plot.getDomainAxis().getLabelFont());
          //				marker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT);
          //				marker.setLabelOffset(new RectangleInsets(10.0, 0.0, 0.0, 0.0));

          marker.setLabelAnchor(RectangleAnchor.BOTTOM);
          marker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT);
          marker.setLabelOffsetType(LengthAdjustmentType.CONTRACT);

          plot.addDomainMarker(marker, Layer.BACKGROUND);
        }
      //
      //			marker = new CategoryMarker("elephant");
      //			marker.setOutlinePaint(null);
      //			marker.setPaint(new Color(150, 150, 150));
      //			plot.addDomainMarker(marker, Layer.BACKGROUND);

      //			CategoryPointerAnnotation p = new CategoryPointerAnnotation("", "mouse", 0.5,
      // Math.toRadians(270.0));
      //			p.setPaint(Color.RED);
      //			plot.addAnnotation(p);

      //			for (int i = 0; i < cols.length; i++)
      //				cols[i] = ColorUtil.grayscale(cols[i]);

      for (int i = 0; i < dataset.getRowCount(); i++) {
        //				renderer.setSeriesShape(i, p1);

        //				double ratio = i / (double) (dataset.getRowCount() - 1);
        //				System.out.println(i + " " + ratio);
        //				//			renderer.setSeriesPaint(i, ColorGradient.get2ColorGradient(ratio, Color.BLACK,
        // Color.LIGHT_GRAY));
        //				//				renderer.setSeriesPaint(i, new ColorGradient(new Color(200, 0, 0),
        // Color.LIGHT_GRAY, new Color(150,
        //				//						150, 255)).getColor(ratio));
        //				renderer.setSeriesPaint(i, new ColorGradient(new Color(0, 0, 200), Color.LIGHT_GRAY,
        // new Color(150,
        //						150, 255)).getColor(ratio));
        renderer.setSeriesPaint(i, cols[i]);

        renderer.setSeriesOutlinePaint(i, Color.BLACK);
        renderer.setSeriesFillPaint(i, Color.BLACK);

        if (shapes != null) renderer.setSeriesShape(i, shapes[i]);

        float thick = 1.0f;

        //				if ((dataset.getRowCount() == 2 || dataset.getRowCount() == 3) && i == 1)
        //					renderer.setSeriesStroke(i, new BasicStroke(thick, BasicStroke.CAP_ROUND,
        // BasicStroke.JOIN_ROUND,
        //							1.0f, new float[] { 6f * thick, 1.5f * thick }, 3f * thick));
        //				else if ((dataset.getRowCount() == 2 || dataset.getRowCount() == 3) && i == 2)
        //					renderer.setSeriesStroke(i, new BasicStroke(thick, BasicStroke.CAP_ROUND,
        // BasicStroke.JOIN_ROUND,
        //							1.0f, new float[] { 1.5f * thick, 1.5f * thick }, 3f * thick));
        //				else
        renderer.setSeriesStroke(
            i, new BasicStroke(thick, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

        // , 1.0f,new float[] { dash, 2 * thick }, dash / 2));

      }

      if (yAxisRange != null)
        ((NumberAxis) plot.getRangeAxis()).setRange(yAxisRange[0], yAxisRange[1]);
      if (yAxisRangePerValue.containsKey(valueProperty))
        ((NumberAxis) plot.getRangeAxis())
            .setRange(
                yAxisRangePerValue.get(valueProperty)[0], yAxisRangePerValue.get(valueProperty)[1]);
      if (yAxisTickUnitsPerValue.containsKey(valueProperty))
        ((NumberAxis) plot.getRangeAxis())
            .setTickUnit(new NumberTickUnit(yAxisTickUnitsPerValue.get(valueProperty)));

      // ((NumberAxis) plot.getRangeAxis()).setAutoRangeIncludesZero(true);

      CategoryAxis axis = plot.getDomainAxis();

      //			axis.setTickLabelsVisible(true);

      if (c == null) {
        c = chart;
      } else if (combinedP == null) {
        combinedP = new CombinedDomainCategoryPlot(new CategoryAxis(xAxisLabel));
        combinedP.setOrientation(PlotOrientation.VERTICAL);
        combinedP.add(c.getCategoryPlot());
        combinedP.add(chart.getCategoryPlot());
        c = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, combinedP, false);
        c.setBackgroundPaint(new Color(0, 0, 0, 0));
        c.addLegend(chart.getLegend());
        axis = plot.getDomainAxis();
      } else {
        combinedP.add(chart.getCategoryPlot());
      }

      if (rotateXLabels == XLabelsRotation.diagonal)
        axis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
      if (rotateXLabels == XLabelsRotation.vertical) {
        axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
        axis.setMaximumCategoryLabelWidthRatio(1.0f);
      }
      axis.setLowerMargin(0);
      axis.setUpperMargin(0);
      if (!showDomainAxis) axis.setVisible(false);
    }
    ChartPanel cp = new ChartPanel(c);
    return cp;
  }
Exemplo n.º 19
0
  /** Confirm that cloning works. */
  public void testCloning() {
    LineAndShapeRenderer r1 = new LineAndShapeRenderer();
    Rectangle2D shape = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0);
    Rectangle2D baseShape = new Rectangle2D.Double(11.0, 12.0, 13.0, 14.0);
    r1.setShape(shape);
    r1.setBaseShape(baseShape);
    r1.setBaseLegendShape(new Rectangle(4, 3, 2, 1));
    r1.setBaseLegendTextFont(new Font("Dialog", Font.PLAIN, 3));
    r1.setBaseLegendTextPaint(new Color(1, 2, 3));

    LineAndShapeRenderer r2 = null;
    try {
      r2 = (LineAndShapeRenderer) r1.clone();
    } catch (CloneNotSupportedException e) {
      e.printStackTrace();
    }
    assertTrue(r1 != r2);
    assertTrue(r1.getClass() == r2.getClass());
    assertTrue(r1.equals(r2));

    r1.setSeriesVisible(0, Boolean.FALSE);
    assertFalse(r1.equals(r2));
    r2.setSeriesVisible(0, Boolean.FALSE);
    assertTrue(r1.equals(r2));

    r1.setSeriesVisibleInLegend(0, Boolean.FALSE);
    assertFalse(r1.equals(r2));
    r2.setSeriesVisibleInLegend(0, Boolean.FALSE);
    assertTrue(r1.equals(r2));

    r1.setSeriesPaint(0, Color.black);
    assertFalse(r1.equals(r2));
    r2.setSeriesPaint(0, Color.black);
    assertTrue(r1.equals(r2));

    r1.setSeriesFillPaint(0, Color.yellow);
    assertFalse(r1.equals(r2));
    r2.setSeriesFillPaint(0, Color.yellow);
    assertTrue(r1.equals(r2));

    r1.setSeriesOutlinePaint(0, Color.yellow);
    assertFalse(r1.equals(r2));
    r2.setSeriesOutlinePaint(0, Color.yellow);
    assertTrue(r1.equals(r2));

    r1.setSeriesStroke(0, new BasicStroke(2.2f));
    assertFalse(r1.equals(r2));
    r2.setSeriesStroke(0, new BasicStroke(2.2f));
    assertTrue(r1.equals(r2));

    r1.setSeriesOutlineStroke(0, new BasicStroke(2.2f));
    assertFalse(r1.equals(r2));
    r2.setSeriesOutlineStroke(0, new BasicStroke(2.2f));
    assertTrue(r1.equals(r2));

    shape.setRect(4.0, 3.0, 2.0, 1.0);
    assertFalse(r1.equals(r2));
    r2.setShape(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0));
    assertTrue(r1.equals(r2));

    baseShape.setRect(4.0, 3.0, 2.0, 1.0);
    assertFalse(r1.equals(r2));
    r2.setBaseShape(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0));
    assertTrue(r1.equals(r2));

    r1.setSeriesShape(0, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertFalse(r1.equals(r2));
    r2.setSeriesShape(0, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertTrue(r1.equals(r2));

    r1.setSeriesItemLabelsVisible(0, Boolean.TRUE);
    assertFalse(r1.equals(r2));
    r2.setSeriesItemLabelsVisible(0, Boolean.TRUE);
    assertTrue(r1.equals(r2));

    r1.setSeriesItemLabelPaint(0, Color.red);
    assertFalse(r1.equals(r2));
    r2.setSeriesItemLabelPaint(0, Color.red);
    assertTrue(r1.equals(r2));

    r1.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition());
    assertFalse(r1.equals(r2));
    r2.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition());
    assertTrue(r1.equals(r2));

    r1.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition());
    assertFalse(r1.equals(r2));
    r2.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition());
    assertTrue(r1.equals(r2));

    r1.setSeriesCreateEntities(0, Boolean.FALSE);
    assertFalse(r1.equals(r2));
    r2.setSeriesCreateEntities(0, Boolean.FALSE);
    assertTrue(r1.equals(r2));

    r1.setLegendShape(0, new Rectangle(9, 7, 3, 4));
    assertFalse(r1.equals(r2));
    r2.setLegendShape(0, new Rectangle(9, 7, 3, 4));
    assertTrue(r1.equals(r2));

    r1.setBaseLegendShape(new Rectangle(3, 4, 1, 5));
    assertFalse(r1.equals(r2));
    r2.setBaseLegendShape(new Rectangle(3, 4, 1, 5));
    assertTrue(r1.equals(r2));

    r1.setLegendTextFont(1, new Font("Dialog", Font.PLAIN, 33));
    assertFalse(r1.equals(r2));
    r2.setLegendTextFont(1, new Font("Dialog", Font.PLAIN, 33));
    assertTrue(r1.equals(r2));

    r1.setBaseLegendTextFont(new Font("Dialog", Font.PLAIN, 11));
    assertFalse(r1.equals(r2));
    r2.setBaseLegendTextFont(new Font("Dialog", Font.PLAIN, 11));
    assertTrue(r1.equals(r2));

    r1.setLegendTextPaint(3, Color.red);
    assertFalse(r1.equals(r2));
    r2.setLegendTextPaint(3, Color.red);
    assertTrue(r1.equals(r2));

    r1.setBaseLegendTextPaint(Color.green);
    assertFalse(r1.equals(r2));
    r2.setBaseLegendTextPaint(Color.green);
    assertTrue(r1.equals(r2));
  }
Exemplo n.º 20
0
  /** A check for cloning. */
  public void testCloning2() {
    LineAndShapeRenderer r1 = new LineAndShapeRenderer();
    r1.setBasePaint(Color.blue);
    r1.setBaseLegendTextPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    LineAndShapeRenderer r2 = null;
    try {
      r2 = (LineAndShapeRenderer) r1.clone();
    } catch (CloneNotSupportedException e) {
      e.printStackTrace();
    }
    assertTrue(r1 != r2);
    assertTrue(r1.getClass() == r2.getClass());
    assertTrue(r1.equals(r2));

    MyRendererChangeListener listener = new MyRendererChangeListener();
    r2.addChangeListener(listener);
    r2.setBasePaint(Color.red);
    assertTrue(listener.lastEvent.getRenderer() == r2);
    assertFalse(r1.hasListener(listener));
  }