/**
   * 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;
  }
  /**
   * 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;
  }
示例#3
0
  public JFreeChart createChart(SelectedChart chart) {
    assert (chart != null);

    CategoryAxis domainAxis = new CategoryAxis("Date");
    plot = new CombinedDomainCategoryPlot(domainAxis);
    if (drawingSupplier == null) {
      drawingSupplier = plot.getDrawingSupplier();
    } else {
      plot.setDrawingSupplier(drawingSupplier);
    }

    switch (chart) {
      case LINE:
        plot.add(trendPlot, 1);
        break;

      case BAR:
        plot.add(sizePlot, 1);
        break;

      case BOTH:
        plot.add(trendPlot, 1);
        plot.add(sizePlot, 2);
        break;

      default:
        assert (false);
    }

    JFreeChart result = new JFreeChart(null, null, plot, true);

    result.removeLegend();

    return result;
  }
示例#4
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;
  }