private static JFreeChart createChart(CategoryDataset categorydataset) {
   JFreeChart jfreechart =
       ChartFactory.createBarChart(
           "Bar Chart Demo 1",
           "Category",
           "Value",
           categorydataset,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
   categoryplot.setDomainGridlinesVisible(true);
   categoryplot.setRangeCrosshairVisible(true);
   categoryplot.setRangeCrosshairPaint(Color.blue);
   NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
   numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
   barrenderer.setDrawBarOutline(false);
   GradientPaint gradientpaint =
       new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
   GradientPaint gradientpaint1 =
       new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
   GradientPaint gradientpaint2 =
       new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
   barrenderer.setSeriesPaint(0, gradientpaint);
   barrenderer.setSeriesPaint(1, gradientpaint1);
   barrenderer.setSeriesPaint(2, gradientpaint2);
   barrenderer.setLegendItemToolTipGenerator(
       new StandardCategorySeriesLabelGenerator("Tooltip: {0}"));
   CategoryAxis categoryaxis = categoryplot.getDomainAxis();
   categoryaxis.setCategoryLabelPositions(
       CategoryLabelPositions.createUpRotationLabelPositions(0.52359877559829882D));
   return jfreechart;
 }
  private JFreeChart getChart() {
    final Calendar now = Calendar.getInstance();
    final DefaultCategoryDataset sourceSet = new DefaultCategoryDataset();
    final boolean legend = false;
    final boolean tooltips = false;
    final boolean urls = false;

    final StringBuffer stringBuffer = new StringBuffer();
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 3; ++j) {

        now.add(Calendar.DAY_OF_YEAR, 1);

        stringBuffer.setLength(0);

        sourceSet.addValue(
            new Integer(stringBuffer.append(i).append(j).toString()),
            String.valueOf(i),
            now.getTime());
      }
    }

    return ChartFactory.createBarChart(
        "fooTitle",
        "fooYLabel",
        "fooXLabel",
        sourceSet,
        PlotOrientation.VERTICAL,
        legend,
        tooltips,
        urls);
  }
  /**
   * @param response
   * @param type
   * @param alphaList
   * @param title
   * @param xTitle
   * @param yTitle
   */
  protected void createChart(
      final CollStatInfo csi,
      final Vector<Pair<String, Integer>> list,
      final String xTitle,
      final String yTitle) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (Pair<String, Integer> p : list) {
      dataset.addValue(p.second, p.first, "");
    }

    // if (StringUtils.isEmpty(csi.getInstName()))
    // {
    //    csi.setInstName(getProviderNameFromInstCode(csi.getProviderId()));
    // }

    JFreeChart chart =
        ChartFactory.createBarChart(
            csi.getTitle(), xTitle, yTitle, dataset, PlotOrientation.VERTICAL, true, true, false);

    // chart.getCategoryPlot().setRenderer(new CustomColorBarChartRenderer());

    chart.setBackgroundPaint(new Color(228, 243, 255));

    try {
      Integer hashCode = csi.hashCode();
      csi.setChartFileName(hashCode + ".png");
      DataOutputStream dos =
          new DataOutputStream(
              new FileOutputStream(new File("reports/charts/" + csi.getChartFileName())));
      ChartUtilities.writeChartAsPNG(dos, chart, 700, 600);

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
 private void saveChart(final DefaultCategoryDataset dataset) throws IOException {
   final JFreeChart chart =
       ChartFactory.createBarChart(
           "HtmlUnit implemented properties and methods for " + browserVersion_.getNickname(),
           "Objects",
           "Count",
           dataset,
           PlotOrientation.HORIZONTAL,
           true,
           true,
           false);
   final CategoryPlot plot = (CategoryPlot) chart.getPlot();
   final NumberAxis axis = (NumberAxis) plot.getRangeAxis();
   axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   final LayeredBarRenderer renderer = new LayeredBarRenderer();
   plot.setRenderer(renderer);
   plot.setRowRenderingOrder(SortOrder.DESCENDING);
   renderer.setSeriesPaint(0, new GradientPaint(0, 0, Color.green, 0, 0, new Color(0, 64, 0)));
   renderer.setSeriesPaint(1, new GradientPaint(0, 0, Color.blue, 0, 0, new Color(0, 0, 64)));
   renderer.setSeriesPaint(2, new GradientPaint(0, 0, Color.red, 0, 0, new Color(64, 0, 0)));
   ImageIO.write(
       chart.createBufferedImage(1200, 2400),
       "png",
       new File(
           getArtifactsDirectory() + "/properties-" + browserVersion_.getNickname() + ".png"));
 }
  private static void generateChart(
      String benchmark, DefaultCategoryDataset dataset, int benchmarkCount) {
    JFreeChart chart =
        ChartFactory.createBarChart(
            benchmark,
            "framework",
            "throughput",
            dataset,
            PlotOrientation.HORIZONTAL,
            true,
            false,
            false);

    CategoryPlot plot = chart.getCategoryPlot();
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setItemMargin(0);
    notSoUglyPlease(chart);

    String pngFile = getOutputName(benchmark);

    try {
      int height = 100 + benchmarkCount * 20;
      ChartUtilities.saveChartAsPNG(new File(pngFile), chart, 700, height);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
 private JFreeChart formChart() {
   DefaultCategoryDataset data = new DefaultCategoryDataset();
   String dateString = request.getParameter("date");
   Date date = null;
   if (dateString != null && (!dateString.equals("null"))) {
     date = DayTransformer.transform(dateString);
   } else {
     date = new Date(System.currentTimeMillis());
   }
   String[][] storeSellingDis =
       saleperformanceManage.getStoreSellingDis(DayTransformer.transformToMonth(date));
   for (int i = 0; i < storeSellingDis.length; i++) {
     data.setValue(
         Double.parseDouble(storeSellingDis[i][1]), storeSellingDis[i][0], storeSellingDis[i][0]);
   }
   JFreeChart barChart =
       ChartFactory.createBarChart(
           "店铺销售分布图", "店铺名称", "销售额", data, PlotOrientation.VERTICAL, true, true, false);
   CategoryPlot plot = (CategoryPlot) barChart.getCategoryPlot();
   BarRenderer renderer = (BarRenderer) plot.getRenderer();
   // 显示条目标签
   renderer.setBaseItemLabelsVisible(true);
   // 设置条目标签生成器,在JFreeChart1.0.6之前可以通过renderer.setItemLabelGenerator(CategoryItemLabelGenerator
   // generator)方法实现,但是从版本1.0.6开始有下面方法代替
   renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
   // 设置条目标签显示的位置,outline表示在条目区域外,baseline_center表示基于基线且居中
   renderer.setBasePositiveItemLabelPosition(
       new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
   barChart.getLegend().setItemFont(new Font("黑体", Font.BOLD, 15)); // 设置引用标签字体
   barChart.getTitle().setFont(new Font("华文行楷", Font.BOLD, 32));
   return barChart;
 }
 private JFreeChart createChart(CategoryDataset setCategory) {
   JFreeChart chart =
       ChartFactory.createBarChart(
           this.chartTitle, "", "", setCategory, PlotOrientation.VERTICAL, true, true, false);
   CategoryPlot plot = (CategoryPlot) chart.getPlot();
   plot.addRangeMarker(ChartUtil.getAverageMarker(this.average), Layer.FOREGROUND);
   BookModel model = this.mainFrame.getBookModel();
   Session session = model.beginTransaction();
   StrandDAOImpl daoStrand = new StrandDAOImpl(session);
   List strands = daoStrand.findAll();
   model.commit();
   Color[] colors = new Color[strands.size()];
   int i = 0;
   Object iObject = strands.iterator();
   while (((Iterator) iObject).hasNext()) {
     Strand strand = (Strand) ((Iterator) iObject).next();
     colors[i] = ColorUtil.darker(strand.getJColor(), 0.25D);
     i++;
   }
   iObject = (BarRenderer) plot.getRenderer();
   for (int j = 0; j < setCategory.getRowCount(); j++) {
     Color color = colors[(j % colors.length)];
     ((BarRenderer) iObject).setSeriesPaint(j, color);
   }
   return chart;
 }
Exemple #8
0
  @Override
  public JFreeChart createChart(FacesContext context) {
    JFreeChart chart;

    if (!getIs3D()) {
      chart =
          ChartFactory.createBarChart(
              getTitle(),
              getDomainAxisLabel(),
              getRangeAxisLabel(),
              (CategoryDataset) dataset,
              plotOrientation(getOrientation()),
              getLegend(),
              false,
              false);
    } else {
      chart =
          ChartFactory.createBarChart3D(
              getTitle(),
              getDomainAxisLabel(),
              getRangeAxisLabel(),
              (CategoryDataset) dataset,
              plotOrientation(getOrientation()),
              getLegend(),
              false,
              false);
    }

    configureTitle(chart.getTitle());
    configureLegend(chart.getLegend());

    return chart;
  }
  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);
  }
  public NetflowTotalByIPChart(String title, String filename) {

    TotalsCSVReader reader =
        new TotalsCSVReader(filename, TotalsCSVReader.IP, TotalsCSVReader.OCTETS);
    HashMap<String, Integer> mappeddata = reader.getTotalsItems();
    Integer val;

    /* Create a simple Bar chart
     */
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (String protocol : mappeddata.keySet()) {
      val = mappeddata.get(protocol);
      dataset.setValue(val.intValue(), "Netflow", protocol);
    }

    JFreeChart chart =
        ChartFactory.createBarChart(
            "Total by IP",
            "IP Address",
            "Octets",
            dataset,
            PlotOrientation.VERTICAL,
            false,
            true,
            false);
    // create and display a frame...
    frame = new ChartFrame(title, chart);
    frame.pack();
  }
  private void btnPictorialViewActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnPictorialViewActionPerformed
    // TODO add your handling code here:
    DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset();

    for (Product product : supplier.getProductCatalog().getProductCatalog()) {
      categoryDataset.setValue(product.getSoldQuantity(), "Units", product.getProdName());
    }
    JFreeChart freeChart =
        ChartFactory.createBarChart(
            "Sales Report",
            "Product",
            "Units",
            categoryDataset,
            PlotOrientation.VERTICAL,
            false,
            true,
            false);

    CategoryPlot categoryPlot = freeChart.getCategoryPlot();
    categoryPlot.setRangeGridlinePaint(Color.BLACK);
    ChartFrame cf = new ChartFrame("Sales Report", freeChart);
    cf.setVisible(true);
    cf.setSize(450, 300);
  } // GEN-LAST:event_btnPictorialViewActionPerformed
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private static JFreeChart createchart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            "Bar Chart Demo 1", // chart
            // title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
            );

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

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // ******************************************************************
    // More than 150 demo applications are included with the JFreeChart
    // Developer Guide...for more information, see:
    //
    // > http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    // renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
  }
 /**
  * Create a bar chart with sample data in the range -3 to +3.
  *
  * @return The chart.
  */
 private static JFreeChart createBarChart() {
   Number[][] data =
       new Integer[][] {
         {new Integer(-3), new Integer(-2)},
         {new Integer(-1), new Integer(1)},
         {new Integer(2), new Integer(3)}
       };
   CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data);
   return ChartFactory.createBarChart("Bar Chart", "Domain", "Range", dataset);
 }
Exemple #14
0
  public BarChart_AWT(String applicationTitle, String chartTitle, int nbpers) {
    JFreeChart barChart =
        ChartFactory.createBarChart(
            chartTitle,
            "Rôles",
            "Fréquence",
            createDataset(nbpers),
            PlotOrientation.VERTICAL,
            true,
            true,
            false);

    ChartPanel chartPanel = new ChartPanel(barChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    this.setTitle(applicationTitle);
    this.dispose();

    JPanel top = new JPanel();
    JPanel body = new JPanel();

    body.add(chartPanel);
    top.add(prec);
    top.add(next);

    this.getContentPane().add(top, BorderLayout.NORTH);
    this.getContentPane().add(body, BorderLayout.CENTER);

    prec.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (increment > 0) {
              increment--;
            }
            chart = new BarChart_AWT("Statistiques", iofile.nb_to_name(increment), increment);
            chart.pack();
            chart.setLocationRelativeTo(null);
            hidden();
            chart.setVisible(true);
          }
        });

    next.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (increment < 11) {
              increment++;
            }
            chart = new BarChart_AWT("Statistiques", iofile.nb_to_name(increment), increment);
            chart.pack();
            chart.setLocationRelativeTo(null);
            hidden();
            chart.setVisible(true);
          }
        });
  }
  /**
   * Displays a signal (using the JFreeChart package).
   *
   * @param useChart if set to true, the signal is displaied as a bar chart (this is used for
   *     histograms).
   */
  public void display(boolean useChart) {

    JFreeChart chart;
    int nbSamples = getNbSamples();

    if (useChart) {
      String[] categories = new String[nbSamples];
      for (int i = 0; i < nbSamples; i++) {
        categories[i] = data.getX(i).toString();
      }
      String[] categoryNames = {"Histogram"};
      double[][] categoryData = new double[1][nbSamples];
      for (int i = 0; i < nbSamples; i++) {
        categoryData[0][i] = data.getY(i).doubleValue();
      }

      CategoryDataset categoryDataset =
          DatasetUtilities.createCategoryDataset(categoryNames, categories, categoryData);

      chart =
          ChartFactory.createBarChart(
              "Histogram", // Title
              "Data Value", // X axis label
              "Number of Elements", // Y axis label
              categoryDataset, // dataset
              PlotOrientation.VERTICAL, // orientation
              true, // legends
              true, // tool tips
              true);
    } else {
      XYDataset xyDataSet = new XYSeriesCollection(this.data);
      chart =
          ChartFactory.createXYLineChart(
              "Example Dataset", // Title
              "Abscissa", // X axis label
              "Ordinate", // Y axis label
              xyDataSet, // dataset
              PlotOrientation.VERTICAL, // orientation
              true, // legends
              true, // tool tips
              true); // urls

      XYPlot plot = (XYPlot) chart.getPlot();
      XYItemRenderer r = plot.getRenderer();
      if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setSeriesShapesVisible(0, true);
        renderer.setSeriesShapesFilled(0, true);
      }
    }

    ChartFrame frame = new ChartFrame("Frame Title", chart);
    frame.setVisible(true);
    frame.setSize(512, 512);
  }
Exemple #16
0
  public JFreeChart getChart() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(5, "Sales", "2007");
    dataset.setValue(6, "Sales", "2008");

    JFreeChart chart =
        ChartFactory.createBarChart(
            "BarChart", "Year", "Sales", dataset, PlotOrientation.VERTICAL, false, true, true);

    return chart;
  }
Exemple #17
0
 /**
  * A simple test for the auto-range calculation looking at a NumberAxis used as the range axis for
  * a CategoryPlot.
  */
 @Test
 public void testAutoRange1() {
   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);
   CategoryPlot plot = (CategoryPlot) chart.getPlot();
   NumberAxis axis = (NumberAxis) plot.getRangeAxis();
   assertEquals(axis.getLowerBound(), 0.0, EPSILON);
   assertEquals(axis.getUpperBound(), 210.0, EPSILON);
 }
  /**
   * This method renders the chart given a dataset on the respective panel
   *
   * @param dataset
   * @param type (0: Assets, 1: Liabilities, 2: Income, 3: Expense)
   */
  private ChartPanel renderBarChart(DefaultCategoryDataset dataset, int type) {

    // Customize the chart's title
    String title = "";
    switch (type) {
      case 0:
        title = "Assets";
        break;
      case 1:
        title = "Liabilities";
        break;
      case 2:
        title = "Income";
        break;
      case 3:
        title = "Expenses";
        break;
    }

    // Create JFreeChart with dataSet
    JFreeChart newChart =
        ChartFactory.createBarChart(
            title, "Categories", "Amount", dataset, PlotOrientation.VERTICAL, false, true, false);

    // Change the chart's visual properties
    CategoryPlot chartPlot = newChart.getCategoryPlot();
    chartPlot.setBackgroundPaint(Color.WHITE); // to set the background color of the chart as white
    BarRenderer chartRenderer = (BarRenderer) chartPlot.getRenderer();

    // Customize the chart's color
    switch (type) {
      case 0:
        chartRenderer.setSeriesPaint(0, new Color(50, 170, 20));
        break;
      case 1:
        chartRenderer.setSeriesPaint(0, new Color(200, 30, 20));
        break;
      case 2:
        chartRenderer.setSeriesPaint(0, new Color(13, 92, 166));
        break;
      case 3:
        chartRenderer.setSeriesPaint(0, new Color(255, 205, 50));
        break;
    }
    chartRenderer.setBarPainter(new StandardBarPainter()); // to disable the default 'shiny look'

    // Create the chart panel
    ChartPanel newChartPanel =
        new ChartPanel(newChart, 350, 200, 200, 100, 800, 300, true, true, true, true, true, true);
    newChartPanel.setSize(270, 200);

    return newChartPanel;
  }
Exemple #19
0
 private static JFreeChart createBarChart(CategoryDataset dataset) {
   JFreeChart chart =
       ChartFactory.createBarChart(
           "Classificações", // Titulo
           "Nome de ficheiro", // Eixo X
           "Classificação média", // Eixo Y
           dataset, // Dados para o grafico
           PlotOrientation.VERTICAL, // Orientacao do grafico
           false,
           false,
           false); // exibir: legendas, tooltips, url
   return chart;
 }
 /**
  * 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);
 }
  /**
   * Method returns a constructed, fully customised chart.
   *
   * @param dataset - dataset from the de-serialized Statistics object
   * @return JFreeChart chart
   */
  private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            "Time taken/Cells covered Performance", // Title of the chart
            "", // X Axis label
            "Time taken", // Y axis label
            dataset, // Data used for the chart
            PlotOrientation.VERTICAL, // Orientation of the chart to be drawn
            false, // Legend
            true, // Tooltips
            false // URL
            );

    // Display an additional label undeneath the bar chart to tell the user to hover over the bar
    // chart to see more deatils
    TextTitle legendText = new TextTitle("* Hover over the bar to see the cells covered.");
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);

    // Background for the chart
    chart.setBackgroundPaint(Color.white);

    // Store reference to the plot to customise it
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // Y axis should display integers only (so that the time taken is given in second integers)
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // Set the colours for the graphs
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));

    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    // Set up the X axis so that the title appears diagonal
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    return chart;
  }
  private void createBarchart(
      String title,
      String categoryLabel,
      String valueLabel,
      PlotData[] data,
      String[] dataLabels,
      String filename) {

    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    int maxDataLength = 0;

    for (int i = 0; i < dataLabels.length; i++) {
      for (int j = 0; j < data[i].getData().length; j++) {
        dataSet.addValue(data[i].getData()[j], dataLabels[i], data[i].getLabels()[j]);
      }
      if (maxDataLength < data[i].getData().length) {
        maxDataLength = data[i].getData().length;
      }
    }

    JFreeChart chart =
        ChartFactory.createBarChart(
            title,
            categoryLabel,
            valueLabel,
            dataSet,
            PlotOrientation.VERTICAL,
            dataLabels.length > 1, // display legend
            false,
            false);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis();
    xAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
    xAxis.setMaximumCategoryLabelLines(6);

    // chart.setBackgroundPaint(ChartColor.WHITE);
    int width = 50 + maxDataLength * 170;
    if (maxDataLength < 3) {
      width += 170;
    }
    int height = 400;
    try {
      File file = new File(contextPath + filename);
      ChartUtilities.saveChartAsPNG(file, chart, width, height);
    } catch (IOException e) {
      LOG.warn("createBarchart(): ", e);
    }
  }
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            "", // chart
            // title
            xLabel, // domain axis label
            yLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
            );

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

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
  }
Exemple #24
0
 /**
  * 生成JFreeChart
  *
  * @return
  */
 private JFreeChart getJFreeChart() {
   CategoryDataset dataset = getCategoryDataset();
   JFreeChart chart =
       ChartFactory.createBarChart(
           "2010年上半年销售量", // 图表标题
           "月份", // x轴标签
           "销售量(单位:本)", // y轴标签
           dataset, // 数据集
           PlotOrientation.VERTICAL, // 图表方向:水平、垂直
           false, // 是否显示图例(对于简单的柱状图必须是false)
           false, // 是否生成工具
           false // 是否生成URL链接
           );
   return chart;
 }
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            "SubCategoryAxis Demo 1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
            );

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    SubCategoryAxis axis = new SubCategoryAxis(null);
    axis.addSubCategory("S1");
    axis.addSubCategory("S2");
    axis.addSubCategory("S3");
    plot.setDomainAxis(axis);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    ChartUtilities.applyCurrentTheme(chart);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    return chart;
  }
Exemple #26
0
  private JFreeChart getBarChart() {
    // Load the data, if necessary
    loadData();

    // Create the vertical bar chart
    final JFreeChart chart =
        ChartFactory.createBarChart(
            getTitle(),
            "",
            "",
            getCategoryDataset(),
            PlotOrientation.HORIZONTAL,
            false,
            true,
            false);
    final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    categoryplot.setRangePannable(true);
    categoryplot.setNoDataMessage("No data available");

    final BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setItemLabelAnchorOffset(9D);
    barrenderer.setBaseItemLabelsVisible(true);
    barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    // barrenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{1} = {2}", new
    // DecimalFormat("0")));
    final CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryMargin(0.25D);

    categoryaxis.setUpperMargin(0.02D);
    categoryaxis.setLowerMargin(0.02D);
    final NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setUpperMargin(0.10000000000000001D);
    ChartUtilities.applyCurrentTheme(chart);

    //    if (useLegend())
    //    {
    //      // pieplot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1})"));
    //      chart.getLegend().setPosition(RectangleEdge.RIGHT);
    //      // pieplot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("{0}:
    // {2}%"));
    //    }

    return chart;
  }
  /**
   * Creates a new demo.
   *
   * @param title the frame title.
   */
  public MouseListenerDemo2(String title) {

    super(title);
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(1.0, "S1", "C1");
    dataset.addValue(4.0, "S1", "C2");
    dataset.addValue(3.0, "S1", "C3");
    dataset.addValue(5.0, "S1", "C4");
    dataset.addValue(5.0, "S1", "C5");
    dataset.addValue(6.0, "S1", "C6");
    dataset.addValue(7.0, "S1", "C7");
    dataset.addValue(8.0, "S1", "C8");
    dataset.addValue(5.0, "S2", "C1");
    dataset.addValue(7.0, "S2", "C2");
    dataset.addValue(6.0, "S2", "C3");
    dataset.addValue(8.0, "S2", "C4");
    dataset.addValue(4.0, "S2", "C5");
    dataset.addValue(4.0, "S2", "C6");
    dataset.addValue(3.0, "S2", "C7");
    dataset.addValue(1.0, "S2", "C8");
    dataset.addValue(4.0, "S3", "C1");
    dataset.addValue(3.0, "S3", "C2");
    dataset.addValue(2.0, "S3", "C3");
    dataset.addValue(3.0, "S3", "C4");
    dataset.addValue(6.0, "S3", "C5");
    dataset.addValue(3.0, "S3", "C6");
    dataset.addValue(4.0, "S3", "C7");
    dataset.addValue(3.0, "S3", "C8");

    JFreeChart chart =
        ChartFactory.createBarChart(
            "MouseListenerDemo2",
            "Category",
            "Value",
            dataset,
            PlotOrientation.VERTICAL,
            true,
            true,
            false);

    // add the chart to a panel...
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.addChartMouseListener(this);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
  }
  @Override
  protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) {
    // Get the time function
    String func = ServletRequestUtils.getStringParameter(request, "func", "hour");

    UsageStatisticsService svc = Context.getService(UsageStatisticsService.class);

    int[][] timeStats = new int[0][0];
    String xAxisLabel = null;
    String[] categories = null;
    if (func.equals("hour")) {
      timeStats = svc.getHourStats(getFromDate(), getUntilInclusiveDate(), getLocation());
      xAxisLabel = ContextProvider.getMessage("usagestatistics.chart.hour");
    } else if (func.equals("dayofweek")) {
      timeStats = svc.getDayOfWeekStats(getFromDate(), getUntilInclusiveDate(), getLocation());
      xAxisLabel = ContextProvider.getMessage("usagestatistics.chart.day");
      categories = ContextProvider.getMessage("usagestatistics.chart.dayNames").split("\\|");
    }

    String yAxisLabel = ContextProvider.getMessage("usagestatistics.chart.records");
    String seriesView = ContextProvider.getMessage("usagestatistics.results.views");
    String seriesUpdates = ContextProvider.getMessage("usagestatistics.results.updates");

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int c = 0; c < timeStats.length; c++) {
      dataset.addValue(
          timeStats[c][0], seriesView, (categories != null) ? categories[c] : (c + ""));
      dataset.addValue(
          timeStats[c][1], seriesUpdates, (categories != null) ? categories[c] : (c + ""));
    }

    JFreeChart chart =
        ChartFactory.createBarChart(
            null, // Chart title
            xAxisLabel, // Domain axis label
            yAxisLabel, // Range axis label
            dataset, // Data
            PlotOrientation.VERTICAL, // Orientation
            true, // Include legend
            false, // Tooltips?
            false // URLs?
            );

    return chart;
  }
Exemple #29
0
 private static JFreeChart createFieldCountChart(
     Stats.RecordStats recordStats, String which, String name) {
   if (recordStats == null) return null;
   List<Stats.Counter> sorted = sort(recordStats.fieldCount.counterMap.values());
   DefaultCategoryDataset data = new DefaultCategoryDataset();
   for (Stats.Counter counter : sorted) data.addValue(counter.count, "Count", counter.value);
   JFreeChart chart =
       ChartFactory.createBarChart(
           String.format("Unique fields per record in %s of %s", which, name),
           "Unique field count",
           "Record count",
           data,
           PlotOrientation.VERTICAL,
           false,
           true,
           false);
   return finishBarChart(chart); // , new Color(220, 20, 60), new Color(50, 205, 50));
 }
Exemple #30
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);
  }