public void loadDataToGrafik() throws IOException {
    DefaultCategoryDataset dataset = (DefaultCategoryDataset) this.generateData();
    chart =
        ChartFactory.createBarChart(
            "Statistik Pendidikan Dosen",
            "Prodi",
            "Jumlah Dosen",
            dataset,
            PlotOrientation.HORIZONTAL,
            true,
            true,
            false);
    chart.setBackgroundPaint(new Color(0xCC, 0xFF, 0xCC));

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final CategoryItemRenderer renderer1 = plot.getRenderer();
    renderer1.setSeriesPaint(0, Color.red);
    renderer1.setSeriesPaint(1, Color.yellow);
    renderer1.setSeriesPaint(2, Color.green);
    BarRenderer br = (BarRenderer) renderer1;
    br.setShadowVisible(false);

    br.setShadowVisible(false);
    BufferedImage bi = chart.createBufferedImage(900, 1500, BufferedImage.TRANSLUCENT, null);
    byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);
    AImage image = new AImage("Bar Chart", bytes);
    chartImg.setContent(image);
    btnExport.setDisabled(false);
  }
Пример #2
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_;
  }