public BoxplotChart(String title, String xAxisTitle, String yAxisTitle) {
    super();
    dataset = new DefaultBoxAndWhiskerCategoryDataset();

    CategoryAxis xAxis = new CategoryAxis("Type");
    NumberAxis yAxis = new NumberAxis("Value");
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    chart = new JFreeChart(title, plot);

    Font font = new Font("Helvetica", Font.BOLD, 12);
    xAxis.setLabelFont(font);
    xAxis.setLabel(xAxisTitle);
    yAxis.setLabelFont(font);
    yAxis.setLabel(yAxisTitle);

    // Making it pretty
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    chart.setBackgroundPaint(Color.white);
    chart.setTextAntiAlias(true);
    yAxis.setAutoRange(true);
    colorGenerator = new ColorGenerator();
    datasetIndex = 0;

    chart.getLegend().setPosition(RectangleEdge.BOTTOM);
    chart.getLegend().setBorder(1, 1, 1, 1);
  }
 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;
 }
  /**
   * 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;
  }
示例#4
0
    protected void configurePlot(CategoryPlot plot) {
      plot.setBackgroundPaint(Color.WHITE);
      plot.setOutlinePaint(null);
      plot.setRangeGridlinesVisible(true);
      plot.setRangeGridlinePaint(Color.black);

      configureRenderer((LineAndShapeRenderer) plot.getRenderer());
      configureDomainAxis(plot);
    }
示例#5
0
  @Override
  protected void formatPlot(Plot plot) {
    CategoryPlot cPlot = (CategoryPlot) plot;
    cPlot.setBackgroundPaint(format.getBackgroundColor());
    cPlot.setRangeGridlinePaint(format.getGridColor());
    cPlot.setDomainGridlinePaint(format.getGridColor());

    formatRenderer((BarRenderer) cPlot.getRenderer());
    setRange();
  }
  /**
   * 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;
  }
示例#7
0
  private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart =
        ChartFactory.createLineChart(
            "Daily Stock Report", // chart title
            "Type", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
            );
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    // customise the range axis...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);
    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesStroke(
        0,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {10.0f, 6.0f},
            0.0f));
    renderer.setSeriesStroke(
        1,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {6.0f, 6.0f},
            0.0f));
    renderer.setSeriesStroke(
        2,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {2.0f, 6.0f},
            0.0f));
    return chart;
  }
示例#8
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;
  }
示例#9
0
  @Override
  protected JFreeChart createGraph() {
    final JFreeChart chart =
        ChartFactory.createLineChart(
            null, // chart title
            null, // unused
            yLabel, // range axis label
            categoryDataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
            );

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

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

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

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

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

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

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

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

    return chart;
  }
示例#10
0
  /**
   * Creates a chart.
   *
   * @param dataset a dataset.
   * @return A chart.
   */
  private JFreeChart createChart(Gantt gantt, IntervalCategoryDataset dataset) {

    JFreeChart chart =
        ChartFactory.createGanttChart(
            "Solution Gantt", // title
            "Operators", // x-axis label
            "Time", // y-axis label
            null, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
            );

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    Paint p = getBackgroundColorGradient();
    chart.setBackgroundPaint(p);

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.black);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setOrientation(PlotOrientation.HORIZONTAL);

    DateAxis xaxis = (DateAxis) plot.getRangeAxis();
    xaxis.setDateFormatOverride(new VertexDateFormat());
    xaxis.setPositiveArrowVisible(true);

    DefaultDrawingSupplier d = new DefaultDrawingSupplier();

    plot.setDrawingSupplier(d);
    GanttRenderer ren = new MyGanttRenderer();

    for (GanttElement element : gantt.getElementSet()) {
      ((MyGanttRenderer) ren).addColor(element.getTitle(), element.getColor());
    }

    ren.setSeriesItemLabelsVisible(0, false);
    ren.setSeriesVisibleInLegend(0, false);
    ren.setSeriesItemLabelGenerator(0, new IntervalCategoryItemLabelGenerator());
    ren.setSeriesToolTipGenerator(0, new MapperGanttToolTipGenerator());

    ren.setAutoPopulateSeriesShape(false);

    plot.setRenderer(ren);

    plot.setDataset(dataset);
    return chart;
  }
示例#11
0
  /**
   * 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;
  }
示例#12
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;
  }
  public void createChart() {

    CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset();
    report =
        ChartFactory.createStackedBarChart(
            this.datasetStrategy.getTitle(),
            this.datasetStrategy.getYAxisLabel(),
            this.datasetStrategy.getXAxisLabel(),
            categorydataset,
            PlotOrientation.HORIZONTAL,
            true,
            true,
            false);
    // report.setBackgroundPaint( Color.lightGray );
    report.setAntiAlias(false);
    report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d));
    CategoryPlot categoryplot = (CategoryPlot) report.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.lightGray);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    if (datasetStrategy instanceof CloverBarChartStrategy
        || datasetStrategy instanceof MultiCloverBarChartStrategy) {
      numberaxis.setRange(0.0D, StackedBarChartRenderer.NUMBER_AXIS_RANGE);
      numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
      numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    numberaxis.setLowerMargin(0.0D);
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setItemLabelsVisible(true);
    stackedbarrenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setItemLabelFont(
        StackedBarRenderer.DEFAULT_VALUE_LABEL_FONT.deriveFont(Font.BOLD));
    int height =
        (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT * 2)
            + ChartUtils.STANDARD_BARCHART_ADDITIONAL_HEIGHT
            + 10;
    if (height > ChartUtils.MINIMUM_HEIGHT) {
      super.setHeight(height);
    } else {
      super.setHeight(ChartUtils.MINIMUM_HEIGHT);
    }
    Paint[] paints = this.datasetStrategy.getPaintColor();

    for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) {
      stackedbarrenderer.setSeriesPaint(i, paints[i]);
    }
  }
 private static JFreeChart createChart(CategoryDataset categorydataset, String title) {
   JFreeChart jfreechart =
       ChartFactory.createStackedBarChart(
           title, "分类:区域", "短信数", categorydataset, PlotOrientation.HORIZONTAL, true, true, false);
   jfreechart.setBackgroundPaint(Color.white);
   CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
   categoryplot.setBackgroundPaint(Color.lightGray);
   categoryplot.setRangeGridlinePaint(Color.white);
   categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
   StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
   stackedbarrenderer.setDrawBarOutline(false);
   stackedbarrenderer.setMaximumBarWidth(0.1);
   stackedbarrenderer.setItemLabelsVisible(true);
   return jfreechart;
 }
示例#15
0
  /**
   * 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;
  }
示例#16
0
  public static void createChart() {
    // criação do gráfico
    JFreeChart chart =
        ChartFactory.createLineChart(
            "Gráfico da Função: " + funcao, // titulo do gráfico
            "Resultados", // eixoy
            "Valores de Entrada", // eixox
            dataset, // base de dados
            PlotOrientation.VERTICAL,
            false, // legenda
            true, // dica, popup
            false // urls
            );
    // personalizando o gráfico

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

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

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

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

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

    ChartFrame frame = new ChartFrame("Gráfico - Calculadora Função Atividade 2", chart);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            "Bar Chart Demo 8", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // 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.setRangeGridlinePaint(Color.white);

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

    // disable bar outlines...
    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
  }
示例#18
0
  /** Creates a trend chart. */
  public JFreeChart createChart(CategoryDataset ds) {
    final JFreeChart chart =
        ChartFactory.createLineChart(
            null, // chart title
            null, // unused
            null, // range axis label
            ds, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
            );

    chart.setBackgroundPaint(Color.white);

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

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

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

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

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

    return chart;
  }
示例#19
0
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createStackedBarChart(
            "Public Opinion : Torture of Prisoners",
            "Country", // domain axis label
            "%", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
            );

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);
    chart.getTitle().setMargin(2.0, 0.0, 0.0, 0.0);

    TextTitle tt =
        new TextTitle(
            "Source: http://news.bbc.co.uk/1/hi/world/6063386.stm",
            new Font("Dialog", Font.PLAIN, 11));
    tt.setPosition(RectangleEdge.BOTTOM);
    tt.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    tt.setMargin(0.0, 0.0, 4.0, 4.0);
    chart.addSubtitle(tt);

    TextTitle t =
        new TextTitle(
            "(*) Across 27,000 respondents in 25 countries", new Font("Dialog", Font.PLAIN, 11));
    t.setPosition(RectangleEdge.BOTTOM);
    t.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    t.setMargin(4.0, 0.0, 2.0, 4.0);
    chart.addSubtitle(t);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    LegendItemCollection items = new LegendItemCollection();
    items.add(
        new LegendItem(
            "Against all torture",
            null,
            null,
            null,
            new Rectangle2D.Double(-6.0, -3.0, 12.0, 6.0),
            Color.green));
    items.add(
        new LegendItem(
            "Some degree permissible",
            null,
            null,
            null,
            new Rectangle2D.Double(-6.0, -3.0, 12.0, 6.0),
            Color.red));
    plot.setFixedLegendItems(items);
    plot.setInsets(new RectangleInsets(5, 5, 5, 20));
    LegendTitle legend = new LegendTitle(plot);
    legend.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legend);

    plot.setBackgroundPaint(Color.lightGray);
    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());
    rangeAxis.setUpperMargin(0.0);

    // 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.green, 0.0f, 0.0f, new Color(0, 64, 0));
    Paint gp1 = new Color(0, 0, 0, 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(0, Color.green);
    renderer.setSeriesPaint(1, gp1);
    // renderer.setSeriesPaint(2, gp2);
    renderer.setSeriesPaint(2, Color.red);

    return chart;
  }
  private void createGraphs() {
    long time = System.currentTimeMillis();
    System.out.println("Creating graphs...");
    final String[] rowKeys = {"to BB", "to Pot", "to Stack", "to Previous"};

    for (int game = 0; game < distributions.length; game++) {
      for (int position = 0; position < distributions[game].length; position++) {
        for (int stage = 0; stage < distributions[game][position].length; stage++) {
          for (int action = 1; action < distributions[game][position][stage].length; action++) {
            DefaultCategoryDataset dataset = new DefaultCategoryDataset();
            for (int tox = 0; tox < distributions[game][position][stage][action].length; tox++) {
              for (int group = 0;
                  group < distributions[game][position][stage][action][tox].length;
                  group++) {
                //								String colKey = "";
                //								colKey = (group % 5 == 0) ?
                // group+"/"+(double)group/10+"/"+(double)group/2+"/"+(double)group/2 :
                // String.valueOf(group);
                dataset.addValue(
                    round(
                        (double) distributions[game][position][stage][action][tox][group]
                            / sumActions[game][position][stage][action]),
                    rowKeys[tox],
                    (group == 100) ? ">=100" : String.valueOf(group));
              }
            }
            String name = "";
            if (game == HU) name += "HU_";
            else if (game == SH) name += "SH_";
            else if (game == FR) name += "FR_";
            name += position + "_";
            if (stage == PREFLOP) name += "Preflop_";
            else if (stage == FLOP) name += "Flop_";
            else if (stage == TURN) name += "Turn_";
            else if (stage == RIVER) name += "River_";
            if (action == CALL) name += "CALL";
            else if (action == BET) name += "BET";
            else if (action == RAISE) name += "RAISE";
            else if (action == _3BET) name += "3BET";
            else if (action == _4BET) name += "4BET";
            else if (action == _5BET) name += "5BET";

            JFreeChart chart =
                ChartFactory.createLineChart(
                    name,
                    "bucket of amount",
                    "% of actions",
                    dataset,
                    PlotOrientation.VERTICAL,
                    true,
                    false,
                    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.white);
            plot.setDomainGridlinePaint(Color.white);
            plot.setRangeGridlinePaint(Color.lightGray);

            // set the range axis to display integers only...
            //			        	CategoryAxis rangeAxis = plot.getDomainAxis();
            //			        	rangeAxis.setCategoryLabelPositionOffset(0);

            // disable bar outlines...
            //						BarRenderer renderer = (BarRenderer) plot.getRenderer();
            //						renderer.setDrawBarOutline(false);
            //						renderer.setShadowVisible(false);
            try {
              ChartUtilities.saveChartAsJPEG(
                  new File(folder + "graphs\\" + name + ".jpg"), chart, 1500, 500);
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        }
      }
    }
    System.out.println("Creating Graphs finished in " + (System.currentTimeMillis() - time) + "ms");
  }
示例#21
0
  private String geraTabelaMeses(
      String tituloSLA,
      Integer idAcordoNivelServico,
      HttpServletRequest request,
      UsuarioDTO usuarioDto)
      throws ParseException, IOException {
    ControleGenerateSLAPorAcordoNivelServicoByMesAno
        controleGenerateSLAPorAcordoNivelServicoByMesAno =
            new ControleGenerateSLAPorAcordoNivelServicoByMesAno();
    int m = UtilDatas.getMonth(UtilDatas.getDataAtual());
    int y = UtilDatas.getYear(UtilDatas.getDataAtual());
    int mPesq = (m + 1); // Faz este incremento de 1, pois logo que entrar no laço, faz um -1
    String strTable = "<table width='100%' border='1'>";
    String strHeader = "";
    String strDados = "";
    strHeader += "<tr>";
    strDados += "<tr>";

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < 6; i++) {
      mPesq = (mPesq - 1);
      if (mPesq <= 0) {
        mPesq = 12;
        y = y - 1;
      }
      strHeader = strHeader + "<td colspan='2' style='border:1px solid black; text-align:center'>";
      strHeader = strHeader + (mPesq + "/" + y);
      strHeader = strHeader + "</td>";

      List lst =
          controleGenerateSLAPorAcordoNivelServicoByMesAno.execute(idAcordoNivelServico, y, mPesq);
      double qtdeDentroPrazo = 0;
      double qtdeForaPrazo = 0;
      if (lst != null && lst.size() > 0) {
        for (Iterator itSLA = lst.iterator(); itSLA.hasNext(); ) {
          Object[] objs = (Object[]) itSLA.next();
          if (((String) objs[0]).indexOf("Fora") > -1 || ((String) objs[0]).indexOf("Out") > -1) {
            qtdeForaPrazo = (Double) objs[2];
          } else {
            qtdeDentroPrazo = (Double) objs[2];
          }
        }
      }
      double qtdeDentroPrazoPerc = 0;
      if ((qtdeDentroPrazo + qtdeForaPrazo) > 0) {
        qtdeDentroPrazoPerc = (qtdeDentroPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100;
      }
      double qtdeForaPrazoPerc = 0;
      if ((qtdeDentroPrazo + qtdeForaPrazo) > 0) {
        qtdeForaPrazoPerc = (qtdeForaPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100;
      }
      strDados = strDados + "<td style='border:1px solid black'>";
      strDados = strDados + UtilFormatacao.formatDouble(qtdeDentroPrazoPerc, 2) + "%";
      strDados = strDados + "</td>";
      strDados = strDados + "<td style='border:1px solid black'>";
      strDados = strDados + UtilFormatacao.formatDouble(qtdeForaPrazoPerc, 2) + "%";
      strDados = strDados + "</td>";

      dataset.setValue(
          new Double(qtdeDentroPrazoPerc),
          UtilI18N.internacionaliza(request, "sla.avaliacao.noprazo"),
          "" + (mPesq + "/" + y));
      dataset.setValue(
          new Double(qtdeForaPrazoPerc),
          UtilI18N.internacionaliza(request, "sla.avaliacao.foraprazo"),
          "" + (mPesq + "/" + y));
    }
    strHeader += "</tr>";
    strDados += "</tr>";

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            tituloSLA, // chart title
            UtilI18N.internacionaliza(request, "sla.avaliacao.indicadores"), // domain axis label
            UtilI18N.internacionaliza(request, "sla.avaliacao.resultado"), // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
            );

    // 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.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.red, 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 / 6.0));

    String nomeImgAval =
        CITCorporeUtil.caminho_real_app
            + "/tempFiles/"
            + usuarioDto.getIdUsuario()
            + "/avalSLAXX_"
            + idAcordoNivelServico
            + ".png";
    String nomeImgAvalRel =
        br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS")
            + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO")
            + "/tempFiles/"
            + usuarioDto.getIdUsuario()
            + "/avalSLAXX_"
            + idAcordoNivelServico
            + ".png";
    File arquivo2 = new File(nomeImgAval);
    if (arquivo2.exists()) {
      arquivo2.delete();
    }
    ChartUtilities.saveChartAsPNG(arquivo2, chart, 500, 200);
    strTable += "<tr>";
    strTable += "<td colspan='12'>";
    strTable += "<img src='" + nomeImgAvalRel + "' border='0'/>";
    strTable += "</td>";
    strTable += "</tr>";

    strTable += strHeader;
    strTable += strDados;

    strTable += "</table>";
    return strTable;
  }
示例#22
0
  public String creatchat(CategoryDataset cr, int ss) {
    JFreeChart chart =
        ChartFactory.createLineChart(
            "先来先服务", "进程", "时间", cr, PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot ccc = (CategoryPlot) chart.getPlot();

    // Plot plo=chart.getPlot();
    // plo.setDrawingSupplier(getSupplier());

    ValueAxis valueaxis = ccc.getRangeAxis(); // getRangeAxis();
    // 数据为整型
    valueaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // 设定显示范围,即总是显示1-10
    if (ss == 1) {
      Image image;
      try {
        image = ImageIO.read(new File("C:/wancheng.png"));
        chart.setBackgroundImage(image);
        chart.setBackgroundImageAlpha(1.0f);
        chart.setBorderPaint(Color.white);
        ccc.setBackgroundPaint(null);
      } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }

      valueaxis.setLowerBound(-1);
      valueaxis.setUpperBound(7);
    } else {
      valueaxis.setLowerBound(-1);
      valueaxis.setUpperBound(7);
    }
    CategoryItemRenderer renderer = ccc.getRenderer();
    renderer.setSeriesPaint(0, Color.YELLOW);
    renderer.setSeriesPaint(1, Color.red);
    renderer.setSeriesPaint(2, Color.green);
    renderer.setSeriesPaint(3, Color.gray);
    renderer.setSeriesPaint(4, Color.cyan);
    renderer.setSeriesPaint(5, Color.magenta);
    renderer.setSeriesPaint(6, Color.pink);

    FileOutputStream fos_jpg = null;
    try {
      if (ss == 1) {
        String chaername = "C:/jincheng.png";
        fos_jpg = new FileOutputStream(chaername);

        // 将报表保存为png文件
        ChartUtilities.writeChartAsPNG(fos_jpg, chart, 500, 510);
        return chaername;
      } else {
        String chaername = "C:/wancheng.png";
        fos_jpg = new FileOutputStream(chaername);

        // 将报表保存为png文件
        ChartUtilities.writeChartAsPNG(fos_jpg, chart, 500, 510);
        return chaername;
      }

    } catch (Exception e) {
      e.printStackTrace();
      return null;
    } finally {
      try {
        fos_jpg.close();
        System.out.println("create time-createTimeXYChar.");
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  public Drawable createChart(ADCDataset dataset, Dimension dimension) {
    JFreeChart chart =
        ChartFactory.createBarChart(
            "", // chart title
            "", // domain axis label
            "", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            false, // legend
            false, // tooltips
            false // urls
            );
    TextTitle textTitle = new TextTitle(dataset.get(Attribute.TITLE), TITLE_FONT);
    textTitle.setPadding(new RectangleInsets(10, 0, 0, 0));
    chart.setTitle(textTitle);

    chart.addLegend(createLegend(dataset.getRowKey(0).toString(), dataset.getRowKey(1).toString()));
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setOutlineVisible(false);
    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeGridlineStroke(new BasicStroke(2));

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoTickUnitSelection(true);
    rangeAxis.setTickUnit(new NumberTickUnit(0.2, percentFormatter()));
    rangeAxis.setAxisLineVisible(true);
    rangeAxis.setLabel(dataset.get(Attribute.Y_AXIS_LABEL));
    rangeAxis.setAxisLineStroke(new BasicStroke(2));
    rangeAxis.setAxisLinePaint(Color.black);
    rangeAxis.setTickMarksVisible(false);
    rangeAxis.setLabelPaint(AXIS_LABEL_COLOR);
    rangeAxis.setLabelFont(AXIS_LABEL_FONT);
    rangeAxis.setLabelInsets(new RectangleInsets(0, 0, 0, 0));
    rangeAxis.setUpperMargin(0);
    rangeAxis.setAutoRange(false);
    rangeAxis.setRange(0, 1);

    CategoryAxis cAxis = plot.getDomainAxis();
    cAxis.setTickMarksVisible(false);
    cAxis.setAxisLinePaint(Color.black);
    cAxis.setAxisLineStroke(new BasicStroke(2));
    cAxis.setLabel(dataset.get(Attribute.X_AXIS_LABEL));
    cAxis.setTickLabelsVisible(true);
    cAxis.setUpperMargin(0.05);
    cAxis.setLowerMargin(0.05);
    cAxis.setTickLabelFont(CAXIS_LABEL_FONT);
    cAxis.setTickLabelPaint(Color.black);
    CustomBarRenderer renderer = new CustomBarRenderer();
    plot.setRenderer(renderer);
    renderer.setDrawBarOutline(false);
    renderer.setBaseItemLabelsVisible(false);
    renderer.setShadowVisible(false);
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setMaximumBarWidth(0.08);
    renderer.setItemMargin(0.01);
    return new JFreeChartDrawable(chart, dimension);
  }
  private BufferedImage generarGraficoBarrasDistribucionResultados(
      String titulo,
      String ejeHorizontal,
      String ejeVertical,
      double[] valores,
      String[] funciones,
      boolean porcentaje,
      boolean leyenda,
      int intervaloAprobacion,
      int anchoImagen,
      int altoImagen) {
    if (valores.length != funciones.length) {
      return null;
    }
    DefaultCategoryDataset pieDataset = new DefaultCategoryDataset();
    for (int i = 0; i < valores.length; i++) {
      pieDataset.addValue(valores[i], "Serie 1", funciones[i]);
    }
    JFreeChart chart =
        ChartFactory.createBarChart(
            titulo,
            ejeHorizontal,
            ejeVertical,
            pieDataset,
            PlotOrientation.VERTICAL,
            leyenda,
            true,
            false);
    chart.setBackgroundPaint(null);
    chart.setBorderVisible(false);
    chart.getTitle().setPaint(LookAndFeelEntropy.COLOR_FUENTE_TITULO_PANEL);
    chart.getTitle().setFont(LookAndFeelEntropy.FUENTE_TITULO_GRANDE);
    if (leyenda) {
      chart.getLegend().setItemFont(LookAndFeelEntropy.FUENTE_REGULAR);
      chart.getLegend().setBackgroundPaint(LookAndFeelEntropy.COLOR_TABLA_PRIMARIO);
    }

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setBackgroundImageAlpha(0.0f);
    plot.setOutlineVisible(false);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    if (porcentaje) {
      rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    final AprobadoDesaprobadoBarRenderer renderer = new AprobadoDesaprobadoBarRenderer();
    renderer.setIntervaloAprobacion(intervaloAprobacion);
    plot.setRenderer(renderer);

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

    this.lastChart = chart;

    // Generamos una imagen
    return chart.createBufferedImage(anchoImagen, altoImagen);
  }
  /** Comienzo de mètodos básicos. */
  private BufferedImage generarGraficoBarrasApiladas(
      String titulo,
      String ejeHorizontal,
      String ejeVertical,
      ArrayList<Serie> series,
      boolean porcentaje,
      boolean leyenda,
      PlotOrientation orientacion,
      int anchoImagen,
      int altoImagen) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (Serie serie : series) {
      if (serie.valores.length != serie.funciones.length) {
        continue;
      }
      for (int i = 0; i < serie.valores.length; i++) {
        dataset.addValue(serie.valores[i], serie.funciones[i], serie.nombre);
      }
    }
    JFreeChart chart =
        ChartFactory.createStackedBarChart(
            titulo,
            ejeHorizontal,
            ejeVertical,
            dataset,
            orientacion,
            leyenda,
            true, // tooltips
            false // urls
            );

    chart.setBackgroundPaint(null);
    chart.getTitle().setPaint(LookAndFeelEntropy.COLOR_FUENTE_TITULO_PANEL);
    chart.getTitle().setFont(LookAndFeelEntropy.FUENTE_TITULO_GRANDE);
    chart.setBorderVisible(false);
    if (leyenda) {
      chart.getLegend().setItemFont(LookAndFeelEntropy.FUENTE_REGULAR);
      chart.getLegend().setBackgroundPaint(LookAndFeelEntropy.COLOR_TABLA_PRIMARIO);
    }

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap(series.get(0).nombre);
    for (Serie serie : series) {
      map.mapKeyToGroup(serie.nombre, serie.nombre);
    }
    renderer.setSeriesToGroupMap(map);
    renderer.setDrawBarOutline(false);
    renderer.setRenderAsPercentages(porcentaje);
    renderer.setItemLabelsVisible(true);
    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());

    for (Serie serie : series) {
      for (int i = 0; i < serie.valores.length; i++) {
        if (Serie.colores.size() - 1 < i || Serie.colores.get(i) == null) {
          Color color = generarColorAleatorio(Color.orange);
          GradientPaint gp = new GradientPaint(0.0f, 0.0f, color, 0.0f, 0.0f, color);
          Serie.colores.add(gp);
        }
        renderer.setSeriesPaint(i, Serie.colores.get(i));
      }
    }

    renderer.setGradientPaintTransformer(
        new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setBackgroundImageAlpha(0.0f);
    plot.setOutlineVisible(false);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    if (porcentaje) {
      rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    domainAxis.setCategoryMargin(0.05);

    plot.setRenderer(renderer);

    // Generamos una imagen
    this.lastChart = chart;
    return chart.createBufferedImage(anchoImagen, altoImagen);
  }
  private BufferedImage generarGraficoBarras(
      String titulo,
      String ejeHorizontal,
      String ejeVertical,
      ArrayList<Serie> series,
      boolean porcentaje,
      boolean leyenda,
      int anchoImagen,
      int altoImagen) {
    DefaultCategoryDataset barDataset = new DefaultCategoryDataset();
    for (Serie serie : series) {
      if (serie.valores.length != serie.funciones.length) {
        continue;
      }
      for (int i = 0; i < serie.valores.length; i++) {
        barDataset.addValue(serie.valores[i], serie.nombre, serie.funciones[i]);
      }
    }

    JFreeChart chart =
        ChartFactory.createBarChart(
            titulo,
            ejeHorizontal,
            ejeVertical,
            barDataset,
            PlotOrientation.VERTICAL,
            leyenda,
            true,
            false);
    chart.setBackgroundPaint(null);
    chart.getTitle().setPaint(LookAndFeelEntropy.COLOR_FUENTE_TITULO_PANEL);
    chart.getTitle().setFont(LookAndFeelEntropy.FUENTE_TITULO_GRANDE);
    chart.setBorderVisible(false);
    if (leyenda) {
      chart.getLegend().setItemFont(LookAndFeelEntropy.FUENTE_REGULAR);
      chart.getLegend().setBackgroundPaint(LookAndFeelEntropy.COLOR_TABLA_PRIMARIO);
    }

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setBackgroundImageAlpha(0.0f);
    plot.setOutlineVisible(false);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    if (porcentaje) {
      rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

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

    for (Serie serie : series) {
      for (int i = 0; i < serie.valores.length; i++) {
        Color color = generarColorAleatorio(Color.orange);
        if (Serie.colores.size() - 1 < i || Serie.colores.get(i) == null) {
          GradientPaint gp = new GradientPaint(0.0f, 0.0f, color, 0.0f, 0.0f, color);
          Serie.colores.add(gp);
        }
        renderer.setSeriesPaint(i, Serie.colores.get(i));
      }
    }

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

    // Generamos una imagen
    this.lastChart = chart;
    return chart.createBufferedImage(anchoImagen, altoImagen);
  }
  public JFreeChart getChart(CategoryDataset dataset) {
    // create the chart...
    final JFreeChart chart =
        ChartFactory.createBarChart3D(
            "Загрузка данных", // chart title
            "Дата", // domain axis label
            "Значение (кб.)", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
            );

    //		#44639C;

    TextTitle title = new TextTitle("Динамика загрузки данных", labelFont);
    //		Paint paint = title.getPaint();
    title.setPaint(new Color(68, 99, 156));
    chart.setTitle(title);

    // 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...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    // final IntervalMarker target = new IntervalMarker(2000000, 3000000);
    // target.setLabel("Ожидаемый диапазон");
    // target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
    // target.setLabelAnchor(RectangleAnchor.LEFT);
    // target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    // target.setPaint(new Color(222, 222, 255, 128));
    // plot.addRangeMarker(target, Layer.BACKGROUND);

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

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

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

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

    return chart;
  }
示例#28
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_;
  }
  /* (non-Javadoc)
   * @see com.alpine.datamining.api.impl.visual.ImageVisualizationType#generateOutPut(com.alpine.datamining.api.AnalyticOutPut)
   */
  @Override
  public VisualizationOutPut generateOutPut(AnalyticOutPut analyzerOutPut) {
    AnalyzerOutPutBoxWhisker obj = null;
    if (analyzerOutPut instanceof AnalyzerOutPutBoxWhisker) {
      obj = (AnalyzerOutPutBoxWhisker) analyzerOutPut;
    }
    List<BoxAndWhiskerItem> list = obj.getItemList();
    BoxAndWhiskerDataset dataset = new BoxAndWhiskerDataset();
    String variableName = null;
    String seriesName = null;
    String typeName = null;

    double[] maxArray = new double[list.size()];
    double[] minArray = new double[list.size()];
    // find max and min
    for (int i = 0; i < list.size(); i++) {
      maxArray[i] = list.get(i).getMax().doubleValue();
      minArray[i] = list.get(i).getMin().doubleValue();
    }

    Arrays.sort(maxArray);
    Arrays.sort(minArray);

    double max = maxArray[maxArray.length - 1];
    double min = minArray[0];

    long n = AlpineMath.adjustUnits(min, max);

    for (BoxAndWhiskerItem item : list) {
      dataset.add(
          item.getMean().doubleValue() / n,
          item.getMedian().doubleValue() / n,
          item.getQ1().doubleValue() / n,
          item.getQ3().doubleValue() / n,
          item.getMin().doubleValue() / n,
          item.getMax().doubleValue() / n,
          0,
          0,
          null,
          item.getSeries(),
          item.getType());
    }
    if (list != null && list.size() > 0) {
      variableName = list.get(0).getVariableName();
      if (variableName == null) variableName = "";
      seriesName = list.get(0).getSeriesName();
      if (seriesName == null) seriesName = "";
      typeName = list.get(0).getTypeName();
      if (typeName == null) typeName = "";
    }

    String yLabel =
        n == 1
            ? variableName
            : variableName
                + " "
                + VisualLanguagePack.getMessage(VisualLanguagePack.UNITS, locale)
                + " ("
                + com.alpine.datamining.api.utility.AlpineMath.powExpression(n)
                + ")";

    final CategoryAxis xAxis = new CategoryAxis(typeName);
    xAxis.setLabelFont(VisualResource.getChartFont());
    final NumberAxis yAxis = new NumberAxis(yLabel);
    yAxis.setLabelFont(VisualResource.getChartFont());
    yAxis.setAutoRangeIncludesZero(false);

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    if (list != null && list.size() < 5) {
      renderer.setMaximumBarWidth(0.2);
      renderer.setItemMargin(0.7);
    }

    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    DrawingSupplier supplier =
        new DefaultDrawingSupplier(
            createPaintArray(),
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
    plot.setDrawingSupplier(supplier);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    final JFreeChart chart = new JFreeChart(" ", VisualResource.getChartFont(), plot, true);
    chart.removeLegend();
    if (!seriesName.trim().equals("")) {
      final TextTitle subtitle = new TextTitle(seriesName, VisualResource.getChartFont());
      chart.addSubtitle(subtitle);
      chart.addLegend(new LegendTitle(plot));
      chart.getLegend().setItemFont(VisualResource.getChartFont());
    }
    JFreeChartImageVisualizationOutPut output = new JFreeChartImageVisualizationOutPut(chart);
    output.setName(analyzerOutPut.getAnalyticNode().getName());
    return output;
  }
  public Demographics(SimpactII state) {
    super("Demographics");

    // create data
    DefaultCategoryDataset data = new DefaultCategoryDataset();
    int[] demographic;
    int numAgents = state.myAgents.size();
    double now =
        Math.min(
            state.numberOfYears * 52,
            state.schedule
                .getTime()); // determine if we are at the end of the simulation or in the middle
    for (int t = timeGranularity;
        t < now;
        t += timeGranularity) { // Go through each time step (skipping the first)
      demographic = new int[numBoxes]; // create an int[] with the number of slots we want

      // go through agents...
      for (int i = 0; i < numAgents; i++) {
        Agent agent = (Agent) state.myAgents.get(i);
        double age = agent.getAge() * 52; // convert age to weeks
        double ageAtT = age - now + t;

        if (agent.getTimeOfAddition() > t || agent.timeOfRemoval < t) {
          continue;
        } // skip if the agent wasn't born yet or has been removed

        ageAtT /= 52; // convert back to years
        int level = (int) Math.min(numBoxes - 1, Math.floor(ageAtT / boxSize));
        demographic[level] += 1; // ...and add them to their delineations level
      }

      // add the delineations to the data
      for (int j = 0; j < numBoxes; j++) {
        data.addValue(demographic[j], j * boxSize + " - " + (j + 1) * boxSize, t + "");
      }
    }

    // create the chart
    JFreeChart chart =
        ChartFactory.createStackedBarChart(
            "Demographics",
            "Time (weeks)",
            "Proportion of the Population",
            data,
            PlotOrientation.VERTICAL,
            true, // legend
            false, // tooltips
            false); // urls

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.getDomainAxis().setCategoryMargin(0.0);

    // change the renderering of the bars
    BarRenderer br = (BarRenderer) plot.getRenderer();
    br.setShadowVisible(false);
    br.setBarPainter(new StandardBarPainter());

    // br.setItemMargin(0.0);
    // plot.setRenderer(br);

    // silly GUI stuff
    ChartPanel chartPanel = new ChartPanel(chart);

    setContentPane(chartPanel);
    pack();
    setVisible(true);
  } // end constructor