예제 #1
1
파일: Chart.java 프로젝트: feihugis/NetCDF
  private JFreeChart buildDifferenceChart(TimeSeriesCollection dataset, String title) {
    // Creat the chart
    JFreeChart chart =
        ChartFactory.createTimeSeriesChart(
            title,
            "Date",
            "Price",
            dataset,
            true, // legend
            true, // tool tips
            false // URLs
            );
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(
        new XYDifferenceRenderer(new Color(112, 128, 222), new Color(112, 128, 222), false));
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(UnitType.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));

    ValueAxis domainAxis = new DateAxis("Date");
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    plot.setDomainAxis(domainAxis);
    plot.setForegroundAlpha(0.5f);

    return chart;
  }
예제 #2
0
  /** Check that the equals() method distinguishes the required fields. */
  public void testEquals() {
    MultiplePiePlot p1 = new MultiplePiePlot();
    MultiplePiePlot p2 = new MultiplePiePlot();
    assertTrue(p1.equals(p2));
    assertTrue(p2.equals(p1));

    p1.setDataExtractOrder(TableOrder.BY_ROW);
    assertFalse(p1.equals(p2));
    p2.setDataExtractOrder(TableOrder.BY_ROW);
    assertTrue(p1.equals(p2));

    p1.setLimit(1.23);
    assertFalse(p1.equals(p2));
    p2.setLimit(1.23);
    assertTrue(p1.equals(p2));

    p1.setAggregatedItemsKey("Aggregated Items");
    assertFalse(p1.equals(p2));
    p2.setAggregatedItemsKey("Aggregated Items");
    assertTrue(p1.equals(p2));

    p1.setAggregatedItemsPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow));
    assertFalse(p1.equals(p2));
    p2.setAggregatedItemsPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow));
    assertTrue(p1.equals(p2));

    p1.setPieChart(ChartFactory.createPieChart("Title", null, true, true, true));
    assertFalse(p1.equals(p2));
    p2.setPieChart(ChartFactory.createPieChart("Title", null, true, true, true));
    assertTrue(p1.equals(p2));
  }
예제 #3
0
  public static void drawPic(String url, String file) throws FileNotFoundException, IOException {
    //		XYSeries xyseries = getXY(url);
    XYSeries xyseries = getXYseries(url);
    XYSeriesCollection xyseriescollection =
        new XYSeriesCollection(); // 再用XYSeriesCollection添加入XYSeries
    // 对象
    xyseriescollection.addSeries(xyseries);

    // 创建主题样式
    StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
    // 设置标题字体
    standardChartTheme.setExtraLargeFont(new Font("隶书", Font.BOLD, 20));
    // 设置图例的字体
    standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 15));
    // 设置轴向的字体
    standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 15));
    // 应用主题样式
    ChartFactory.setChartTheme(standardChartTheme);
    // JFreeChart chart=ChartFactory.createXYAreaChart("xyPoit", "点的标号",
    // "出现次数", xyseriescollection, PlotOrientation.VERTICAL, true, false,
    // false);
    JFreeChart chart =
        ChartFactory.createScatterPlot(
            "决策图", "点密度", "点距离", xyseriescollection, PlotOrientation.VERTICAL, true, false, false);
    //		String file="d:/decision_chart.png";
    try {
      ChartUtilities.saveChartAsPNG(new File(file), chart, 470, 470);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    System.out.println(new java.util.Date() + ": finished drawing the pic in " + file);
  }
예제 #4
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;
  }
예제 #5
0
  /**
   * Cria um grafico de pizza com os dados fornecidos
   *
   * @param titulo <code>String</code> com o titulo do grafico
   * @param listaNomesValores {@code List<NomeValor>} lista com os nomes e valores para o grafico
   * @param legendasAdicionais <code>String...</code> com as legendas adicionais
   * @param graficoEm3D <code>boolean</code> com <code>true</code> se o grafico é em 3D ou não.
   */
  public GraficoPizza(
      String titulo,
      List<NomeValor> listaNomesValores,
      boolean graficoEm3D,
      final String... legendasAdicionais) {
    // Cria um dataSet para inserir os dados que serão passados para a criação do grafico tipo Pie
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    this.graficoEm3D = graficoEm3D;

    // Adiciona os dados ao dataSet deve somar um total de 100%
    double valorUmPorCentoVotos = this.valorUmVotoEmPorCento(listaNomesValores);
    String valor;
    for (NomeValor nomesValores : listaNomesValores) {
      valor = String.format("%.2f%%", nomesValores.getValor() * valorUmPorCentoVotos);
      pieDataset.setValue(nomesValores.getNome() + "(" + valor + ")", nomesValores.getValor());
    }

    // Cria um objeto JFreeChart passando os seguintes parametros
    if (!this.graficoEm3D) {
      this.grafico =
          ChartFactory.createPieChart(
              titulo, // Titulo do grafico
              pieDataset, // DataSet
              true, // Para mostrar ou não a legenda
              true, // Para mostrar ou não os tooltips
              false);
    } else { // em 3D
      this.grafico =
          ChartFactory.createPieChart3D(
              titulo, // Titulo do grafico
              pieDataset, // DataSet
              true, // Para mostrar ou não a legenda
              true, // Para mostrar ou não os tooltips
              false);
    }

    if (this.grafico != null) {
      LegendTitle legenda =
          new LegendTitle(
              new LegendItemSource() {

                @Override
                public LegendItemCollection getLegendItems() {
                  LegendItemCollection legenda = new LegendItemCollection();
                  for (String texto : legendasAdicionais) {
                    legenda.add(new LegendItem(texto));
                  }
                  return legenda;
                }
              });
      float larguraBordaLegenda = 0.6F;
      legenda.setBorder(
          larguraBordaLegenda, larguraBordaLegenda, larguraBordaLegenda, larguraBordaLegenda);
      legenda.setPosition(RectangleEdge.BOTTOM);
      legenda.setHorizontalAlignment(HorizontalAlignment.LEFT);
      this.grafico.addLegend(legenda);
    }
  }
예제 #6
0
  /**
   * 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);
  }
예제 #7
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;
  }
예제 #8
0
  // Pie Chart
  // //////////////////////////////////////////////////////////////////////////////
  protected JScrollPane getGraphPanel() {
    DefaultCategoryDataset dataset;
    if (absPerformance instanceof AbstractPerformance2D) {
      dataset = getDefaultCategoryDataset((AbstractPerformance2D) absPerformance);
    } else {
      dataset = getDefaultCategoryDataset(absPerformance);
    }

    PlotOrientation order = PlotOrientation.VERTICAL;
    if (orientationSort.getValue().equals("Horizontal")) {
      order = PlotOrientation.HORIZONTAL;
    }

    String strCategory = absPerformance.getItemName();
    if (absPerformance instanceof AbstractPerformance2D) {
      if (isItemA) {
        strCategory = ((AbstractPerformance2D) absPerformance).getSecondItemName();
      } else {
        strCategory = ((AbstractPerformance2D) absPerformance).getItemName();
      }
    }
    if (dimSort.getValue().equals("2D")) {
      chart =
          ChartFactory.createStackedBarChart(
              null, strCategory, "time", dataset, order, bLegend, true, false);
    } else if (dimSort.getValue().equals("3D")) {
      chart =
          ChartFactory.createStackedBarChart3D(
              null, strCategory, "time", dataset, order, bLegend, true, false);
    }

    // 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.setRangeGridlinePaint(Color.white);

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

    chartPanel = new ChartPanel(chart, false);
    scrollPane = new JScrollPane(chartPanel);
    return scrollPane;
  }
  ChartPanelShowStatistics(
      String title,
      String timeAxisLabel,
      String valueAxisLabel,
      XYDataset dataset /*, boolean legend, boolean tooltips, boolean urls*/) {
    this();
    // chart = ChartFactory.createTimeSeriesChart(title, timeAxisLabel, valueAxisLabel, dataset);
    chart = ChartFactory.createScatterPlot(title, timeAxisLabel, valueAxisLabel, dataset);
    ChartPanel p = new ChartPanel(chart);
    add(p, BorderLayout.CENTER);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();

    renderer.setBaseShapesVisible(false);
    //		renderer.setBaseShape(itemShape);	// 好像不管用,必须用setSeriesShape
    renderer.setBaseLinesVisible(true);
    //		renderer.setBasePaint(new Color(0));	// 好像不管用,必须用setSeriesPaint

    itemShape = ShapeUtilities.createDiamond((float) 3);
    renderer.setSeriesShape(0, itemShape);
    renderer.setSeriesPaint(0, new Color(255, 0, 0));

    renderer.setSeriesShape(1, itemShape);
    renderer.setSeriesPaint(1, new Color(0, 255, 0));

    renderer.setBaseToolTipGenerator(
        new StandardXYToolTipGenerator(
            "{0}:({1} , {2})",
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), new DecimalFormat("#.00")));
  }
  private static JFreeChart createChart(
      XYDataset dataset,
      String applicationTitle,
      String chartTitle,
      String xlabel,
      String ylabel,
      String name) {
    JFreeChart chart =
        ChartFactory.createScatterPlot(
            chartTitle, xlabel, ylabel, dataset, PlotOrientation.VERTICAL, true, false, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesOutlinePaint(0, Color.black);
    renderer.setUseOutlinePaint(true);
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setTickMarkInsideLength(2.0f);
    domainAxis.setTickMarkOutsideLength(0.0f);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setTickMarkInsideLength(2.0f);
    rangeAxis.setTickMarkOutsideLength(0.0f);

    return chart;
  }
 private static JFreeChart createChart(CategoryDataset categorydataset) {
   JFreeChart jfreechart =
       ChartFactory.createLineChart(
           "Statistical Line Chart Demo 1",
           "Type",
           "Value",
           categorydataset,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   jfreechart.setBackgroundPaint(Color.white);
   CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
   categoryplot.setBackgroundPaint(Color.lightGray);
   categoryplot.setRangeGridlinePaint(Color.white);
   CategoryAxis categoryaxis = categoryplot.getDomainAxis();
   categoryaxis.setUpperMargin(0.0D);
   categoryaxis.setLowerMargin(0.0D);
   NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
   numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   numberaxis.setAutoRangeIncludesZero(true);
   StatisticalLineAndShapeRenderer statisticallineandshaperenderer =
       new StatisticalLineAndShapeRenderer(true, false);
   statisticallineandshaperenderer.setUseSeriesOffset(true);
   categoryplot.setRenderer(statisticallineandshaperenderer);
   return jfreechart;
 }
예제 #12
0
  /**
   * Creates a chart.
   *
   * @param dataset a dataset.
   * @return A chart.
   */
  private static JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart =
        ChartFactory.createTimeSeriesChart(
            "Rapporto Entrata/uscita nel tempo", // title
            "Date", // x-axis label
            "Quantita", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
            );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
      XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
      renderer.setBaseShapesVisible(true);
      renderer.setBaseShapesFilled(true);
      renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("dd-MMM-yyyy"));

    return chart;
  }
예제 #13
0
 private static JFreeChart createChart(CategoryDataset categorydataset) {
   JFreeChart jfreechart =
       ChartFactory.createStackedBarChart3D(
           "Stacked Bar Chart 3D Demo 2",
           "Category",
           "Value",
           categorydataset,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
   NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
   numberaxis.setNumberFormatOverride(new DecimalFormat("0.0%"));
   StackedBarRenderer3D stackedbarrenderer3d = (StackedBarRenderer3D) categoryplot.getRenderer();
   stackedbarrenderer3d.setRenderAsPercentages(true);
   stackedbarrenderer3d.setDrawBarOutline(false);
   stackedbarrenderer3d.setBaseItemLabelGenerator(
       new StandardCategoryItemLabelGenerator(
           "{3}", NumberFormat.getIntegerInstance(), new DecimalFormat("0.0%")));
   stackedbarrenderer3d.setBaseItemLabelsVisible(true);
   stackedbarrenderer3d.setBasePositiveItemLabelPosition(
       new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
   stackedbarrenderer3d.setBaseNegativeItemLabelPosition(
       new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
   return jfreechart;
 }
 /**
  * Creates a chart.
  *
  * @param dataset a dataset.
  * @return The chart.
  */
 private JFreeChart createChart(final IntervalXYDataset dataset) {
   final JFreeChart chart =
       ChartFactory.createHistogram(
           "Histogram Demo", null, null, dataset, PlotOrientation.VERTICAL, true, false, false);
   chart.getXYPlot().setForegroundAlpha(0.75f);
   return chart;
 }
  /**
   * Creates the histogram chart.
   *
   * @param exampleSet
   * @return
   */
  private JFreeChart createHistogramChart(final ExampleSet exampleSet) {
    JFreeChart chart =
        ChartFactory.createHistogram(
            null,
            null,
            null,
            createHistogramDataset(exampleSet),
            PlotOrientation.VERTICAL,
            false,
            false,
            false);
    AbstractAttributeStatisticsModel.setDefaultChartFonts(chart);
    chart.setBackgroundPaint(null);
    chart.setBackgroundImageAlpha(0.0f);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setOutlineVisible(false);
    plot.setRangeZeroBaselineVisible(false);
    plot.setDomainZeroBaselineVisible(false);
    plot.getDomainAxis().setTickLabelsVisible(false);
    plot.setBackgroundPaint(COLOR_INVISIBLE);
    plot.setBackgroundImageAlpha(0.0f);

    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.DATE_TIME));
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);

    return chart;
  }
  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
예제 #17
0
  /**
   * Creates a chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private static JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart =
        ChartFactory.createStackedBarChart3D(
            "Stacked Bar Chart 3D Demo 1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // include legend
            true, // tooltips
            false // urls
            );
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    IntervalMarker m =
        new IntervalMarker(
            5.0, 10.0, Color.gray, new BasicStroke(0.5f), Color.blue, new BasicStroke(0.5f), 0.5f);
    plot.addRangeMarker(m);
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBasePositiveItemLabelPosition(
        new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    renderer.setBaseNegativeItemLabelPosition(
        new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    return chart;
  }
예제 #18
0
파일: Chart.java 프로젝트: feihugis/NetCDF
  private JFreeChart buildChart(TimeSeriesCollection dataset, String title, boolean endPoints) {
    // Create the chart
    JFreeChart chart =
        ChartFactory.createTimeSeriesChart(title, "Date", "Price", dataset, true, true, false);

    // Display each series in the chart with its point shape in the legend
    LegendTitle sl = chart.getLegend();
    // sl.setDisplaySeriesShapes(true);

    // Setup the appearance of the chart
    chart.setBackgroundPaint(Color.white);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(UnitType.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    // Display data points or just the lines?
    if (endPoints) {
      XYItemRenderer renderer = plot.getRenderer();
      if (renderer instanceof StandardXYItemRenderer) {
        StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        // rr.setPlotShapes(true);
        rr.setShapesFilled(true);
        rr.setItemLabelsVisible(true);
      }
    }

    // Tell the chart how we would like dates to read
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    return chart;
  }
  private JFreeChart createChart(final GraphBuilder builder) {
    final JFreeChart chart =
        ChartFactory.createXYLineChart(
            builder.graphTitle(),
            builder.xAxisLabel(),
            builder.yAxisLabel(),
            builder.dataset(),
            PlotOrientation.VERTICAL,
            true, // include legend
            true, // tooltips
            false // urls
            );

    chart.setBackgroundPaint(Color.white);
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final ValueAxis rangeAxis = plot.getRangeAxis();
    // rangeAxis.setRange(0,20);

    final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseItemLabelsVisible(true);

    if (builder.yRange0To1()) {
      chart.getXYPlot().getRangeAxis().setRange(0.0, 1.0);
    }

    return chart;
  }
예제 #20
0
  private void update() {
    UIRegistry.loadAndPushResourceBundle("specify_plugins");

    HistogramDataset dataSet = new HistogramDataset();
    double max = resultSet.getMax();

    dataSet.addSeries(
        getResourceString("SGR_HISTO_DATASERIES"), resultSet.getValues(1.0), 40, 0.0, max);

    JFreeChart chart =
        ChartFactory.createHistogram(
            getResourceString("SGR_HISTO_TITLE"),
            getResourceString("SGR_HISTO_X_AXIS"),
            getResourceString("SGR_HISTO_Y_AXIS"),
            dataSet,
            PlotOrientation.VERTICAL,
            false, // include legend
            true, // tooltips?
            false // URLs?
            );

    UIRegistry.popResourceBundle();

    XYPlot plot = chart.getXYPlot();
    CustomRenderer.setDefaultBarPainter(new StandardXYBarPainter());
    CustomRenderer renderer = new CustomRenderer(dataSet);
    plot.setRenderer(renderer);
    renderer.setMargin(0.1);

    ChartPanel chartPanel = new ChartPanel(chart, true, true, true, true, true);
    removeAll();
    add(chartPanel);
    validate();
  }
  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);
  }
예제 #22
0
파일: Chart.java 프로젝트: feihugis/NetCDF
  public Chart(String title, String timeAxis, String valueAxis, TimeSeries data) {
    try {
      // Build the datasets
      dataset.addSeries(data);

      // Create the chart
      JFreeChart chart =
          ChartFactory.createTimeSeriesChart(
              title, timeAxis, valueAxis, dataset, true, true, false);

      // Setup the appearance of the chart
      chart.setBackgroundPaint(Color.white);
      XYPlot plot = chart.getXYPlot();
      plot.setBackgroundPaint(Color.lightGray);
      plot.setDomainGridlinePaint(Color.white);
      plot.setRangeGridlinePaint(Color.white);
      plot.setAxisOffset(new RectangleInsets(UnitType.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
      plot.setDomainCrosshairVisible(true);
      plot.setRangeCrosshairVisible(true);

      // Tell the chart how we would like dates to read
      DateAxis axis = (DateAxis) plot.getDomainAxis();
      axis.setDateFormatOverride(new SimpleDateFormat("EEE HH"));

      this.add(new ChartPanel(chart));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #23
0
  private static JFreeChart createChart(XYDataset dataset, String exp) {
    JFreeChart chart =
        ChartFactory.createXYLineChart(
            "", "", "", dataset, PlotOrientation.VERTICAL, false, false, false);
    chart.setBorderVisible(false);
    chart.setAntiAlias(true);
    chart.setBackgroundPaint(Color.getHSBColor((float) 0, (float) 0, (float) 0.96));
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);

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

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

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

    // List axisIndices = Arrays.asList(new Integer[] {new Integer(0),
    //        new Integer(1)});
    // plot.mapDatasetToDomainAxes(0, axisIndices);
    // plot.mapDatasetToRangeAxes(0, axisIndices);
    // ChartUtilities.applyCurrentTheme(chart);
    return chart;
  }
예제 #24
0
 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;
 }
 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 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;
 }
예제 #27
0
  public static void main(String[] args) throws Exception {
    DefaultCategoryDataset line_chart_dataset = new DefaultCategoryDataset();
    line_chart_dataset.addValue(15, "schools", "1970");
    line_chart_dataset.addValue(30, "schools", "1980");
    line_chart_dataset.addValue(60, "schools", "1990");
    line_chart_dataset.addValue(120, "schools", "2000");
    line_chart_dataset.addValue(240, "schools", "2010");
    line_chart_dataset.addValue(300, "schools", "2014");

    JFreeChart lineChartObject =
        ChartFactory.createLineChart(
            "Schools Vs Years",
            "Year",
            "Schools Count",
            line_chart_dataset,
            PlotOrientation.VERTICAL,
            true,
            true,
            false);

    int width = 640; /* Width of the image */
    int height = 480; /* Height of the image */
    File lineChart = new File("LineChart.jpeg");
    ChartUtilities.saveChartAsJPEG(lineChart, lineChartObject, width, height);
  }
예제 #28
0
  /**
   * This method renders a line chart of income and expense entries over 1-month intervals
   *
   * @param dataset
   * @return financesLineChart_PNL
   */
  private ChartPanel renderLineChart(XYDataset dataset) {

    // Create JFreeChart with dataSet
    JFreeChart lineChart =
        ChartFactory.createTimeSeriesChart("", "", "Amount", dataset, true, true, false);

    // Change the x-axis (time interval) format
    XYPlot plot = (XYPlot) lineChart.getPlot();
    DateAxis dateAxis = (DateAxis) plot.getDomainAxis();
    dateAxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    // Change the chart's visual properties
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
      XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
      renderer.setBaseShapesVisible(true);
      renderer.setBaseShapesFilled(true);
      renderer.setDrawSeriesLineAsPath(true);
    }

    // Create and format the chart panel
    ChartPanel financesLineChart_PNL =
        new ChartPanel(lineChart, 600, 250, 200, 100, 800, 300, true, true, true, true, true, true);
    financesLineChart_PNL.setSize(800, 300);

    return financesLineChart_PNL;
  }
  protected JFreeChart constructChart(Iteration iteration, Integer timeZoneOffset) {
    // get server timezone
    Calendar cal = Calendar.getInstance();
    TimeZone localTimeZone = cal.getTimeZone();

    // server timezone offset in minutes
    int rawOffset = localTimeZone.getRawOffset() / 60000;

    // get offset difference in minutes
    timeDifferenceMinutes = rawOffset - timeZoneOffset.intValue();

    JFreeChart burndown =
        ChartFactory.createTimeSeriesChart(
            "'" + iteration.getName() + "' burndown",
            DATE_AXIS_LABEL,
            EFFORT_AXIS_LABEL,
            getDataset(iteration),
            true,
            true,
            false);

    formatChartAxes(
        burndown,
        new DateTime(iteration.getStartDate().minusMinutes(timeDifferenceMinutes)),
        new DateTime(iteration.getEndDate()).minusMinutes(timeDifferenceMinutes));

    formatChartStyle(burndown);

    return burndown;
  }
예제 #30
0
  private static JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart =
        ChartFactory.createXYLineChart(
            "Ratings by Age", // Title
            "Age", // X label
            "Average Rating", // Y label
            dataset, // data
            PlotOrientation.VERTICAL, // Orientation
            false, // legend
            false, // tooltips
            false); // urls
    chart.setBorderPaint(Color.white);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    plot.setRenderer(renderer);

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

    return chart;
  }