private static JFreeChart createChart(XYZDataset xyzdataset) {
    JFreeChart jfreechart =
        ChartFactory.createBubbleChart(
            "AGE vs WEIGHT vs WORK",
            "Weight (kg)",
            "AGE",
            xyzdataset,
            PlotOrientation.HORIZONTAL,
            true,
            true,
            false);

    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setForegroundAlpha(0.65F);
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(0, Color.blue);
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setLowerMargin(0.2);
    numberaxis.setUpperMargin(0.5);
    NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setLowerMargin(0.8);
    numberaxis1.setUpperMargin(0.9);

    return jfreechart;
  }
  private JFreeChart createChart(XYZDataset xyzDataSet) {
    NumberAxis numberAxis = new NumberAxis("X");
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberAxis.setLowerMargin(0.0D);
    numberAxis.setUpperMargin(0.0D);
    numberAxis.setAxisLinePaint(Color.white);
    numberAxis.setTickMarkPaint(Color.white);

    NumberAxis numberAxis1 = new NumberAxis("Y");
    numberAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberAxis1.setLowerMargin(0.0D);
    numberAxis1.setUpperMargin(0.0D);
    numberAxis1.setAxisLinePaint(Color.white);
    numberAxis1.setTickMarkPaint(Color.white);

    XYBlockRenderer xyblockrenderer = new XYBlockRenderer();
    PaintScale paintScale;
    if (this.type == MarkovDataDialog.HeatMapType.COMPARISON)
      paintScale = createNewLookupPaintScale();
    else paintScale = new GrayPaintScale();

    //        paintScale.add(-1.0,Color.WHITE );
    xyblockrenderer.setPaintScale(paintScale);

    XYPlot xyplot = new XYPlot(xyzDataSet, numberAxis, numberAxis1, xyblockrenderer);
    xyplot.setBackgroundPaint(Color.white);
    xyplot.setDomainGridlinesVisible(false);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setOutlinePaint(Color.blue);

    JFreeChart jfreechart = new JFreeChart("heat map", xyplot);
    jfreechart.removeLegend();

    NumberAxis numberAxis2 = new NumberAxis("Scale");
    numberAxis2.setAxisLinePaint(Color.white);
    numberAxis2.setTickMarkPaint(Color.white);
    numberAxis2.setRange(-1.0D, 1.0D);
    numberAxis2.setTickLabelFont(new Font("Dialog", 0, 7));
    PaintScaleLegend paintscalelegend = new PaintScaleLegend(paintScale, numberAxis2);
    paintscalelegend.setStripOutlineVisible(false);
    paintscalelegend.setSubdivisionCount(20);
    paintscalelegend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    paintscalelegend.setAxisOffset(5D);
    paintscalelegend.setMargin(new RectangleInsets(5D, 5D, 5D, 5D));
    //        paintscalelegend.setFrame(new BlockBorder(Color.red));
    paintscalelegend.setPadding(new RectangleInsets(10D, 10D, 10D, 10D));
    paintscalelegend.setStripWidth(10D);
    paintscalelegend.setPosition(RectangleEdge.LEFT);
    jfreechart.addSubtitle(paintscalelegend);
    //        ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
  }
 private static JFreeChart createChart(TableXYDataset tablexydataset) {
   DateAxis dateaxis = new DateAxis("Date");
   dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
   dateaxis.setLowerMargin(0.01D);
   dateaxis.setUpperMargin(0.01D);
   NumberAxis numberaxis = new NumberAxis("Count");
   numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   numberaxis.setUpperMargin(0.10000000000000001D);
   StackedXYBarRenderer stackedxybarrenderer = new StackedXYBarRenderer(0.14999999999999999D);
   stackedxybarrenderer.setDrawBarOutline(false);
   stackedxybarrenderer.setBaseItemLabelsVisible(true);
   stackedxybarrenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
   stackedxybarrenderer.setBasePositiveItemLabelPosition(
       new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER));
   stackedxybarrenderer.setBaseToolTipGenerator(
       new StandardXYToolTipGenerator(
           "{0} : {1} = {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0")));
   XYPlot xyplot = new XYPlot(tablexydataset, dateaxis, numberaxis, stackedxybarrenderer);
   JFreeChart jfreechart = new JFreeChart("Holes-In-One / Double Eagles", xyplot);
   jfreechart.removeLegend();
   jfreechart.addSubtitle(new TextTitle("PGA Tour, 1983 to 2003"));
   TextTitle texttitle =
       new TextTitle(
           "http://www.golfdigest.com/majors/masters/index.ssf?/majors/masters/gw20040402albatross.html",
           new Font("Dialog", 0, 8));
   jfreechart.addSubtitle(texttitle);
   jfreechart.setTextAntiAlias(RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
   LegendTitle legendtitle = new LegendTitle(xyplot);
   legendtitle.setBackgroundPaint(Color.white);
   legendtitle.setFrame(new BlockBorder());
   legendtitle.setPosition(RectangleEdge.BOTTOM);
   jfreechart.addSubtitle(legendtitle);
   return jfreechart;
 }
示例#4
0
 private static JFreeChart finishBarChart(JFreeChart chart, Color... colors) {
   CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
   categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
   categoryplot.setRangePannable(true);
   if (colors.length > 0) categoryplot.setRenderer(new CustomRenderer(colors));
   BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
   barrenderer.setItemLabelAnchorOffset(9D);
   barrenderer.setBaseItemLabelsVisible(true);
   barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
   barrenderer.setMaximumBarWidth(0.05);
   barrenderer.setItemMargin(0.03D);
   ItemLabelPosition itemlabelposition =
       new ItemLabelPosition(INSIDE12, CENTER_RIGHT, CENTER_RIGHT, -1.5707963267948966D);
   barrenderer.setBasePositiveItemLabelPosition(itemlabelposition);
   ItemLabelPosition itemlabelposition1 =
       new ItemLabelPosition(OUTSIDE12, CENTER_LEFT, CENTER_LEFT, -1.5707963267948966D);
   barrenderer.setPositiveItemLabelPositionFallback(itemlabelposition1);
   CategoryAxis categoryaxis = categoryplot.getDomainAxis();
   categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
   categoryaxis.setCategoryMargin(0.25D);
   categoryaxis.setUpperMargin(0.02D);
   categoryaxis.setLowerMargin(0.02D);
   NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
   numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   numberaxis.setUpperMargin(0.10000000000000001D);
   ChartUtilities.applyCurrentTheme(chart);
   return chart;
 }
示例#5
0
  private JFreeChart createScatChart(
      BufferedImage image, PaintScale ps, int plotWidth, int plotHeigh) {
    JFreeChart chart_temp =
        ChartFactory.createScatterPlot(
            null,
            null,
            null,
            new XYSeriesCollection(),
            PlotOrientation.VERTICAL,
            false,
            false,
            false);
    chart_temp.getXYPlot().getRangeAxis().setInverted(true);
    chart_temp.setBackgroundPaint(JFreeChart.DEFAULT_BACKGROUND_PAINT);
    XYDataImageAnnotation ann = new XYDataImageAnnotation(image, 0, 0, plotWidth, plotHeigh, true);
    XYPlot plot = (XYPlot) chart_temp.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.getRenderer().addAnnotation(ann, Layer.BACKGROUND);
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    xAxis.setVisible(false);
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    yAxis.setVisible(false);

    NumberAxis scaleAxis = new NumberAxis();
    scaleAxis.setAxisLinePaint(Color.black);
    scaleAxis.setTickMarkPaint(Color.black);
    scaleAxis.setRange(ps.getLowerBound(), ps.getUpperBound());
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 9));
    PaintScaleLegend legend = new PaintScaleLegend(ps, scaleAxis);
    legend.setAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    legend.setMargin(new RectangleInsets(5, 5, 5, 5));
    legend.setStripWidth(10);
    legend.setPosition(RectangleEdge.RIGHT);
    legend.setBackgroundPaint(chart_temp.getBackgroundPaint());
    chart_temp.addSubtitle(legend);

    return chart_temp;
  }
示例#6
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;
  }
示例#7
0
  private JFreeChart getBarChart() {
    // Load the data, if necessary
    loadData();

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

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

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

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

    return chart;
  }
  /**
   * Creates a 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;
  }
示例#9
0
  private ChartPanel getChartPanel(DefaultXYZDataset dataset, int i) {
    String key = (String) dataset.getSeriesKey(0);
    DateAxis yAxis = new DateAxis("Date");
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    yAxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1));

    NumberAxis xAxis = new NumberAxis("Hour");
    xAxis.setUpperMargin(0.0);
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth(1000.0 * 60.0 * 60.0 * 24.0);
    renderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT);

    // range scaling
    PaintScale paintScale;
    if (colorSort.getValue().equals("gray")) // gray scaling
    {
      paintScale = new GrayPaintScale(0.0, maxArray[i]);
    } else {

      int color_max, color_min;
      if (colorSort.getValue().equals("red")) { // red scaling
        color_max = 0xFF33FF;
        color_min = 0xFF3300;
      } else if (colorSort.getValue().equals("blue")) { // blue scaling
        color_max = 0x0033FF;
        color_min = 0x003300;
      } else { // yellow scaling
        color_max = 0xFFFFFF;
        color_min = 0xFFFF00;
      }
      paintScale = new LookupPaintScale(0.0, maxArray[i], new Color(color_max));
      int d = Math.max((color_max - color_min) / ((int) maxArray[i] + 1), 1);
      for (int k = 0; k <= maxArray[i]; k++) {
        ((LookupPaintScale) paintScale)
            .add(new Double(k + 0.5), new Color(color_max - (k + 1) * d));
      }
    }
    renderer.setPaintScale(paintScale);

    XYPlot plot = new XYPlot(dataset, yAxis, xAxis, renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setForegroundAlpha(0.66F);
    JFreeChart chart = new JFreeChart(key, plot);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);

    // adding data ranges
    NumberAxis scaleAxis = new NumberAxis(null);
    scaleAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    scaleAxis.setLowerBound(0.0);
    scaleAxis.setUpperBound(maxArray[i]);
    PaintScaleLegend psl = new PaintScaleLegend(paintScale, scaleAxis);
    psl.setAxisOffset(5.0);
    psl.setPosition(RectangleEdge.BOTTOM);
    psl.setMargin(new RectangleInsets(5, 5, 5, 5));
    chart.addSubtitle(psl);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setBorder(BorderFactory.createLineBorder(Color.lightGray));
    return chartPanel;
  }
  @Override
  public JFreeChart draw(List<ExperimentInfo> exps) {
    List<Integer> firstLayer = new ArrayList<>();
    List<Integer> secondLayer = new ArrayList<>();
    List<Double> performances = new ArrayList<>();

    exps.stream()
        .filter(e -> e.hasResults())
        .forEach(
            e -> {
              List<Integer> layers = e.getLayerTopology();
              assert (layers.size() == 1 || layers.size() == 2);

              firstLayer.add(layers.get(0));

              if (layers.size() == 2) secondLayer.add(layers.get(1));
              else secondLayer.add(0);

              performances.add(e.getResults().getPerformance());
            });

    assert (firstLayer.size() == secondLayer.size() && secondLayer.size() == performances.size());

    double[] xvalues = new double[firstLayer.size()];
    double[] yvalues = new double[secondLayer.size()];
    double[] zvalues = new double[performances.size()];
    for (int i = 0; i < firstLayer.size(); i++) {
      xvalues[i] = firstLayer.get(i);
      yvalues[i] = secondLayer.get(i);
      zvalues[i] = performances.get(i);
    }

    DefaultXYZDataset dataset = new DefaultXYZDataset();

    dataset.addSeries("aaaa", new double[][] {xvalues, yvalues, zvalues});

    NumberAxis xAxis = new NumberAxis("X");
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);

    NumberAxis yAxis = new NumberAxis("Y");
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);

    XYBlockRenderer renderer = new XYBlockRenderer();

    PaintScale scale =
        new GrayPaintScale(
            performances.stream().mapToDouble(d -> d).min().getAsDouble(),
            performances.stream().mapToDouble(d -> d).max().getAsDouble());
    renderer.setPaintScale(scale);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinePaint(Color.white);

    JFreeChart chart = new JFreeChart("XYBlockChartDemo1", plot);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);

    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.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;
  }
示例#12
0
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return a chart.
   */
  private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart =
        ChartFactory.createLineChart(
            "Line Chart Demo 5", // chart title
            "Type", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
            );

    // final StandardLegend legend = (StandardLegend) chart.getLegend();
    // legend.setDisplaySeriesShapes(true);

    final Shape[] shapes = new Shape[3];
    int[] xpoints;
    int[] ypoints;

    // right-pointing triangle
    xpoints = new int[] {-3, 3, -3};
    ypoints = new int[] {-3, 0, 3};
    shapes[0] = new Polygon(xpoints, ypoints, 3);

    // vertical rectangle
    shapes[1] = new Rectangle2D.Double(-2, -3, 3, 6);

    // left-pointing triangle
    xpoints = new int[] {-3, 3, 3};
    ypoints = new int[] {0, -3, 3};
    shapes[2] = new Polygon(xpoints, ypoints, 3);

    final DrawingSupplier supplier =
        new DefaultDrawingSupplier(
            DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            shapes);
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setDrawingSupplier(supplier);

    chart.setBackgroundPaint(Color.yellow);

    // set the stroke for each series...
    plot.getRenderer()
        .setSeriesStroke(
            0,
            new BasicStroke(
                2.0f,
                BasicStroke.CAP_ROUND,
                BasicStroke.JOIN_ROUND,
                1.0f,
                new float[] {10.0f, 6.0f},
                0.0f));
    plot.getRenderer()
        .setSeriesStroke(
            1,
            new BasicStroke(
                2.0f,
                BasicStroke.CAP_ROUND,
                BasicStroke.JOIN_ROUND,
                1.0f,
                new float[] {6.0f, 6.0f},
                0.0f));
    plot.getRenderer()
        .setSeriesStroke(
            2,
            new BasicStroke(
                2.0f,
                BasicStroke.CAP_ROUND,
                BasicStroke.JOIN_ROUND,
                1.0f,
                new float[] {2.0f, 6.0f},
                0.0f));

    // customise the renderer...
    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    // renderer.setDrawShapes(true);
    renderer.setItemLabelsVisible(true);
    // renderer.setLabelGenerator(new StandardCategoryLabelGenerator());

    // customise the range axis...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setUpperMargin(0.12);

    return chart;
  }
示例#13
0
  private JFreeChart display(
      String title, int height, int width, String category, List<Report> toolResults) {

    JFrame f = new JFrame(title);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // averages
    ArrayList<Double> averageFalseRates = new ArrayList<Double>();

    ArrayList<Double> averageTrueRates = new ArrayList<Double>();
    double averageFalseRate = 0;
    double averageTrueRate = 0;

    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series = new XYSeries("Scores");
    for (int i = 0; i < toolResults.size(); i++) {
      Report toolReport = toolResults.get(i);
      OverallResult overallResults = toolReport.getOverallResults().getResults(category);
      series.add(
          overallResults.getFalsePositiveRate() * 100, overallResults.getTruePositiveRate() * 100);
      if (toolReport.isCommercial()) {
        averageFalseRates.add(overallResults.getFalsePositiveRate());

        averageTrueRates.add(overallResults.getTruePositiveRate());
      }
    }

    for (double d : averageFalseRates) {
      averageFalseRate += d;
    }
    averageFalseRate = averageFalseRate / averageFalseRates.size();

    for (double d : averageTrueRates) {
      averageTrueRate += d;
    }
    averageTrueRate = averageTrueRate / averageTrueRates.size();

    series.add(averageFalseRate * 100, averageTrueRate * 100);
    dataset.addSeries(series);
    afr = averageFalseRate;
    atr = averageTrueRate;

    chart =
        ChartFactory.createScatterPlot(
            title,
            "False Positive Rate",
            "True Positive Rate",
            dataset,
            PlotOrientation.VERTICAL,
            true,
            true,
            false);
    String fontName = "Arial";
    DecimalFormat pctFormat = new DecimalFormat("0'%'");

    theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme();
    theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title
    theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title
    theme.setRegularFont(new Font(fontName, Font.PLAIN, 16));
    theme.setSmallFont(new Font(fontName, Font.PLAIN, 12));
    theme.setRangeGridlinePaint(Color.decode("#C0C0C0"));
    theme.setPlotBackgroundPaint(Color.white);
    theme.setChartBackgroundPaint(Color.white);
    theme.setGridBandPaint(Color.red);
    theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    theme.setBarPainter(new StandardBarPainter());
    theme.setAxisLabelPaint(Color.decode("#666666"));
    theme.apply(chart);

    XYPlot xyplot = chart.getXYPlot();
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();

    xyplot.setOutlineVisible(true);

    rangeAxis.setRange(-5, 109.99);
    rangeAxis.setNumberFormatOverride(pctFormat);
    rangeAxis.setTickLabelPaint(Color.decode("#666666"));
    rangeAxis.setMinorTickCount(5);
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setAxisLineVisible(true);
    rangeAxis.setMinorTickMarksVisible(true);
    rangeAxis.setTickMarksVisible(true);
    rangeAxis.setLowerMargin(10);
    rangeAxis.setUpperMargin(10);
    xyplot.setRangeGridlineStroke(new BasicStroke());
    xyplot.setRangeGridlinePaint(Color.lightGray);
    xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setRangeMinorGridlinesVisible(true);

    domainAxis.setRange(-5, 105);
    domainAxis.setNumberFormatOverride(pctFormat);
    domainAxis.setTickLabelPaint(Color.decode("#666666"));
    domainAxis.setMinorTickCount(5);
    domainAxis.setTickUnit(new NumberTickUnit(10));
    domainAxis.setAxisLineVisible(true);
    domainAxis.setTickMarksVisible(true);
    domainAxis.setMinorTickMarksVisible(true);
    domainAxis.setLowerMargin(10);
    domainAxis.setUpperMargin(10);
    xyplot.setDomainGridlineStroke(new BasicStroke());
    xyplot.setDomainGridlinePaint(Color.lightGray);
    xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setDomainMinorGridlinesVisible(true);

    chart.setTextAntiAlias(true);
    chart.setAntiAlias(true);
    chart.removeLegend();
    chart.setPadding(new RectangleInsets(20, 20, 20, 20));
    xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7"));

    //        // setup item labels
    //        XYItemRenderer renderer = xyplot.getRenderer();
    //        Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 7.0f, 7.0f);
    //        for ( int i = 0; i < dataset.getSeriesCount(); i++ ) {
    //            renderer.setSeriesShape(i, circle);
    //            renderer.setSeriesPaint(i, Color.blue);
    //            String label = ""+((String)dataset.getSeries(i).getKey());
    //            int idx = label.indexOf( ':');
    //            label = label.substring( 0, idx );
    //            StandardXYItemLabelGenerator generator = new StandardXYItemLabelGenerator(label);
    //            renderer.setSeriesItemLabelGenerator(i, generator);
    //            renderer.setSeriesItemLabelsVisible(i, true);
    //            ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
    // TextAnchor.BASELINE_CENTER );
    //            renderer.setSeriesPositiveItemLabelPosition(i, position);
    //        }

    makeDataLabels(category, toolResults, xyplot);
    makeLegend(category, toolResults, 57, 48, dataset, xyplot);

    Stroke dashed =
        new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] {6, 3}, 0);
    for (XYDataItem item : (List<XYDataItem>) series.getItems()) {
      double x = item.getX().doubleValue();
      double y = item.getY().doubleValue();
      double z = (x + y) / 2;
      XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue);
      xyplot.addAnnotation(score);
    }

    //        // put legend inside plot
    //        LegendTitle lt = new LegendTitle(xyplot);
    //        lt.setItemFont(theme.getSmallFont());
    //        lt.setPosition(RectangleEdge.RIGHT);
    //        lt.setItemFont(theme.getSmallFont());
    //        XYTitleAnnotation ta = new XYTitleAnnotation(.7, .55, lt, RectangleAnchor.TOP_LEFT);
    //        ta.setMaxWidth(0.48);
    //        xyplot.addAnnotation(ta);

    // draw guessing line
    XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 105, 105, dashed, Color.red);
    xyplot.addAnnotation(guessing);

    XYPointerAnnotation worse =
        makePointer(75, 5, "Worse than guessing", TextAnchor.TOP_CENTER, 90);
    xyplot.addAnnotation(worse);

    XYPointerAnnotation better =
        makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270);
    xyplot.addAnnotation(better);

    XYTextAnnotation stroketext =
        new XYTextAnnotation("                     Random Guess", 88, 107);
    stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT);
    stroketext.setBackgroundPaint(Color.white);
    stroketext.setPaint(Color.red);
    stroketext.setFont(theme.getRegularFont());
    xyplot.addAnnotation(stroketext);

    XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red);
    xyplot.setBackgroundPaint(Color.white);
    xyplot.addAnnotation(strokekey);

    ChartPanel cp =
        new ChartPanel(
            chart, height, width, 400, 400, 1200, 1200, false, false, false, false, false, false);
    f.add(cp);
    f.pack();
    f.setLocationRelativeTo(null);
    //      f.setVisible(true);

    return chart;
  }
  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);
  }