private static JFreeChart createChart(CategoryDataset categorydataset) {
   JFreeChart jfreechart =
       ChartFactory.createBarChart(
           "Bar Chart Demo 1",
           "Category",
           "Value",
           categorydataset,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
   categoryplot.setDomainGridlinesVisible(true);
   categoryplot.setRangeCrosshairVisible(true);
   categoryplot.setRangeCrosshairPaint(Color.blue);
   NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
   numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
   barrenderer.setDrawBarOutline(false);
   GradientPaint gradientpaint =
       new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
   GradientPaint gradientpaint1 =
       new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
   GradientPaint gradientpaint2 =
       new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
   barrenderer.setSeriesPaint(0, gradientpaint);
   barrenderer.setSeriesPaint(1, gradientpaint1);
   barrenderer.setSeriesPaint(2, gradientpaint2);
   barrenderer.setLegendItemToolTipGenerator(
       new StandardCategorySeriesLabelGenerator("Tooltip: {0}"));
   CategoryAxis categoryaxis = categoryplot.getDomainAxis();
   categoryaxis.setCategoryLabelPositions(
       CategoryLabelPositions.createUpRotationLabelPositions(0.52359877559829882D));
   return jfreechart;
 }
 private static JFreeChart createChart(CategoryDataset paramCategoryDataset) {
   JFreeChart localJFreeChart =
       ChartFactory.createAreaChart(
           "Area Chart",
           "Category",
           "Value",
           paramCategoryDataset,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   localJFreeChart.setBackgroundPaint(Color.white);
   TextTitle localTextTitle =
       new TextTitle(
           "An area chart demonstration.  We use this subtitle as an example of what happens when you get a really long title or subtitle.");
   localTextTitle.setPosition(RectangleEdge.TOP);
   localTextTitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.05D, 0.05D, 0.05D, 0.05D));
   localTextTitle.setVerticalAlignment(VerticalAlignment.BOTTOM);
   localJFreeChart.addSubtitle(localTextTitle);
   CategoryPlot localCategoryPlot = (CategoryPlot) localJFreeChart.getPlot();
   localCategoryPlot.setForegroundAlpha(0.5F);
   localCategoryPlot.setDomainGridlinesVisible(true);
   CategoryAxis localCategoryAxis = localCategoryPlot.getDomainAxis();
   localCategoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
   localCategoryAxis.setLowerMargin(0.0D);
   localCategoryAxis.setUpperMargin(0.0D);
   localCategoryAxis.addCategoryLabelToolTip("Type 1", "The first type.");
   localCategoryAxis.addCategoryLabelToolTip("Type 2", "The second type.");
   localCategoryAxis.addCategoryLabelToolTip("Type 3", "The third type.");
   NumberAxis localNumberAxis = (NumberAxis) localCategoryPlot.getRangeAxis();
   localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   localNumberAxis.setLabelAngle(0.0D);
   ChartUtilities.applyCurrentTheme(localJFreeChart);
   return localJFreeChart;
 }
 public Object clone() throws CloneNotSupportedException {
   NumberAxis clone = (NumberAxis) super.clone();
   if (this.numberFormatOverride != null) {
     clone.numberFormatOverride = (NumberFormat) this.numberFormatOverride.clone();
   }
   return clone;
 }
Example #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;
 }
Example #5
0
  public static void main(String[] args) throws IOException {
    JFreeChart chart =
        ChartFactory.createBarChart3D(
            "图书销量统计图",
            "图书", // 目录轴的显示标签
            "销量", // 数值轴的显示标签
            getDataSet(),
            PlotOrientation.VERTICAL, // 设置图表方向
            false,
            false,
            false);

    // 设置标题
    chart.setTitle(new TextTitle("图书销量统计图", new Font("黑体", Font.ITALIC, 22)));
    // 设置图表部分
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    CategoryAxis categoryAxis = plot.getDomainAxis(); // 取得横轴
    categoryAxis.setLabelFont(new Font("宋体", Font.BOLD, 22)); // 设置横轴显示标签的字体
    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // 分类标签以45度倾斜
    categoryAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 18)); // 分类标签字体

    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); // 取得纵轴
    numberAxis.setLabelFont(new Font("宋体", Font.BOLD, 42)); // 设置纵轴显示标签字体
    FileOutputStream fos = null;
    fos = new FileOutputStream("book1.jpg");
    ChartUtilities.writeChartAsJPEG(fos, 1, chart, 800, 600, null);

    fos.close();
  }
  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);
  }
 /**
  * Set lower and upper limits for an ordinate
  *
  * @param i Axis index
  * @param lower Lower limit
  * @param upper Upper limit
  * @param tick Tick unit
  */
 public void setOrdinateRange(int i, double lower, double upper, double tick) {
   NumberAxis e = AxesList.get(i);
   e.setAutoRange(false);
   e.setLowerBound(lower);
   e.setUpperBound(upper);
   e.setTickUnit(new NumberTickUnit(tick));
 }
 private static JFreeChart createChart(CategoryDataset categorydataset) {
   JFreeChart jfreechart =
       ChartFactory.createStackedBarChart3D(
           "Stacked Bar Chart 3D Demo 2",
           "Category",
           "Value",
           categorydataset,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
   NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
   numberaxis.setNumberFormatOverride(new DecimalFormat("0.0%"));
   StackedBarRenderer3D stackedbarrenderer3d = (StackedBarRenderer3D) categoryplot.getRenderer();
   stackedbarrenderer3d.setRenderAsPercentages(true);
   stackedbarrenderer3d.setDrawBarOutline(false);
   stackedbarrenderer3d.setBaseItemLabelGenerator(
       new StandardCategoryItemLabelGenerator(
           "{3}", NumberFormat.getIntegerInstance(), new DecimalFormat("0.0%")));
   stackedbarrenderer3d.setBaseItemLabelsVisible(true);
   stackedbarrenderer3d.setBasePositiveItemLabelPosition(
       new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
   stackedbarrenderer3d.setBaseNegativeItemLabelPosition(
       new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
   return jfreechart;
 }
 private XYPlot createScalabilityPlot(
     List<XYSeries> seriesList,
     String xAxisLabel,
     NumberFormat xAxisNumberFormat,
     String yAxisLabel,
     NumberFormat yAxisNumberFormat) {
   NumberAxis xAxis;
   if (useLogarithmicProblemScale(seriesList)) {
     LogarithmicAxis logarithmicAxis = new LogarithmicAxis(xAxisLabel + " (logarithmic)");
     logarithmicAxis.setAllowNegativesFlag(true);
     xAxis = logarithmicAxis;
   } else {
     xAxis = new NumberAxis(xAxisLabel);
   }
   xAxis.setNumberFormatOverride(xAxisNumberFormat);
   NumberAxis yAxis = new NumberAxis(yAxisLabel);
   yAxis.setNumberFormatOverride(yAxisNumberFormat);
   XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
   int seriesIndex = 0;
   for (XYSeries series : seriesList) {
     XYSeriesCollection seriesCollection = new XYSeriesCollection();
     seriesCollection.addSeries(series);
     plot.setDataset(seriesIndex, seriesCollection);
     XYItemRenderer renderer = createScalabilityPlotRenderer(yAxisNumberFormat);
     plot.setRenderer(seriesIndex, renderer);
     seriesIndex++;
   }
   plot.setOrientation(PlotOrientation.VERTICAL);
   return plot;
 }
Example #10
0
 private XYPlot getLinePlot() throws KeyedException {
   // use a number axis on the left side (default)
   NumberAxis axis = new NumberAxis();
   axis.setAutoRangeIncludesZero(false);
   XYPlot plot = new XYPlot(null, null, axis, null);
   return plot;
 }
 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;
 }
Example #12
0
  private static JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart =
        ChartFactory.createXYLineChart(
            "Ratings by Age", // Title
            "Age", // X label
            "Average Rating", // Y label
            dataset, // data
            PlotOrientation.VERTICAL, // Orientation
            false, // legend
            false, // tooltips
            false); // urls
    chart.setBorderPaint(Color.white);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

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

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

    return chart;
  }
  public void draw(Configuration conf) throws IOException {
    List<Pair<Integer, Integer>> list = new ArrayList<Pair<Integer, Integer>>();
    SequenceFileDirIterator<IntWritable, IntWritable> iterator =
        new SequenceFileDirIterator<IntWritable, IntWritable>(
            inputPath, PathType.LIST, MultipleSequenceOutputFormat.FILTER, null, true, conf);
    while (iterator.hasNext()) {
      Pair<IntWritable, IntWritable> writablePair = iterator.next();
      Pair<Integer, Integer> pair =
          new Pair<Integer, Integer>(writablePair.getFirst().get(), writablePair.getSecond().get());
      list.add(pair);
    }
    iterator.close();
    Collections.sort(
        list,
        new Comparator<Pair<Integer, Integer>>() {
          @Override
          public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) {
            if (o1.getFirst() < o2.getFirst()) {
              return -1;
            }
            return 1;
          }
        });
    XYDataset dataSet = createDataSet(list);
    JFreeChart chart =
        ChartFactory.createXYLineChart(
            title, "", "count", dataSet, PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setNumberFormatOverride(numberFormat);

    BufferedImage image = chart.createBufferedImage(WIDTH, HEIGHT);
    ImageIO.write(image, FORMAT, new File(imgFile));
  }
Example #14
0
  /**
   * Creates and returns a time series chart.
   *
   * <p>A time series chart is an XYPlot with a date axis (horizontal) and a number axis (vertical),
   * and each data item is connected with a line.
   *
   * <p>Note that you can supply a TimeSeriesCollection to this method, as it implements the
   * XYDataset interface.
   *
   * @param title the chart title.
   * @param timeAxisLabel a label for the time axis.
   * @param valueAxisLabel a label for the value axis.
   * @param data the dataset for the chart.
   * @param legend a flag specifying whether or not a legend is required.
   * @param tooltips configure chart to generate tool tips?
   * @param urls configure chart to generate URLs?
   * @return a time series chart.
   */
  public static JFreeChart createTimeSeriesChart(
      String title,
      java.awt.Font titleFont,
      String timeAxisLabel,
      String valueAxisLabel,
      XYDataset data,
      boolean legend,
      boolean tooltips,
      boolean urls) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    timeAxis.setLowerMargin(0.02); // reduce the default margins on the time axis
    timeAxis.setUpperMargin(0.02);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false); // override default
    XYPlot plot = new XYPlot(data, timeAxis, valueAxis, null);

    XYToolTipGenerator tooltipGenerator = null;
    if (tooltips) {
      tooltipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
      // new StandardXYToolTipGenerator(DateFormat.getDateInstance());
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
      urlGenerator = new StandardXYURLGenerator();
    }

    plot.setRenderer(
        new StandardXYItemRenderer(StandardXYItemRenderer.LINES, tooltipGenerator, urlGenerator));

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;
  }
  /**
   * Set lower and upper limits for an ordinate
   *
   * @param axis Axis to configure
   */
  void setOrdinateRange(final NumberAxis axis) {
    axis.setAutoRange(false);
    GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(0, 10, 0, 10));
    final TextField tfMax;
    final TextField tfMin;
    final TextField tfTick;
    final TextField tfFuente;
    grid.add(new Label("Axis"), 0, 0);
    grid.add(new Label(axis.getLabel()), 1, 0);
    grid.add(new Label("Lower"), 0, 1);
    grid.add(tfMin = new TextField(), 1, 1);
    grid.add(new Label("Upper"), 0, 2);
    grid.add(tfMax = new TextField(), 1, 2);
    grid.add(new Label("Space"), 0, 3);
    grid.add(tfTick = new TextField(), 1, 3);

    tfMin.setText(String.valueOf(axis.getLowerBound()));
    tfMax.setText(String.valueOf(axis.getUpperBound()));
    tfTick.setText(String.valueOf(axis.getTickUnit().getSize()));

    new PseudoModalDialog(skeleton, grid, true) {
      @Override
      public boolean validation() {
        axis.setLowerBound(Double.valueOf(tfMin.getText()));
        axis.setUpperBound(Double.valueOf(tfMax.getText()));
        axis.setTickUnit(new NumberTickUnit(Double.valueOf(tfTick.getText())));
        return true;
      }
    }.show();
  }
 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;
 }
Example #17
0
  private static JFreeChart createChart(XYDataset dataset, String exp) {
    JFreeChart chart =
        ChartFactory.createXYLineChart(
            "", "", "", dataset, PlotOrientation.VERTICAL, false, false, false);
    chart.setBorderVisible(false);
    chart.setAntiAlias(true);
    chart.setBackgroundPaint(Color.getHSBColor((float) 0, (float) 0, (float) 0.96));
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);

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

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

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

    // List axisIndices = Arrays.asList(new Integer[] {new Integer(0),
    //        new Integer(1)});
    // plot.mapDatasetToDomainAxes(0, axisIndices);
    // plot.mapDatasetToRangeAxes(0, axisIndices);
    // ChartUtilities.applyCurrentTheme(chart);
    return chart;
  }
 private void saveChart(final DefaultCategoryDataset dataset) throws IOException {
   final JFreeChart chart =
       ChartFactory.createBarChart(
           "HtmlUnit implemented properties and methods for " + browserVersion_.getNickname(),
           "Objects",
           "Count",
           dataset,
           PlotOrientation.HORIZONTAL,
           true,
           true,
           false);
   final CategoryPlot plot = (CategoryPlot) chart.getPlot();
   final NumberAxis axis = (NumberAxis) plot.getRangeAxis();
   axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   final LayeredBarRenderer renderer = new LayeredBarRenderer();
   plot.setRenderer(renderer);
   plot.setRowRenderingOrder(SortOrder.DESCENDING);
   renderer.setSeriesPaint(0, new GradientPaint(0, 0, Color.green, 0, 0, new Color(0, 64, 0)));
   renderer.setSeriesPaint(1, new GradientPaint(0, 0, Color.blue, 0, 0, new Color(0, 0, 64)));
   renderer.setSeriesPaint(2, new GradientPaint(0, 0, Color.red, 0, 0, new Color(64, 0, 0)));
   ImageIO.write(
       chart.createBufferedImage(1200, 2400),
       "png",
       new File(
           getArtifactsDirectory() + "/properties-" + browserVersion_.getNickname() + ".png"));
 }
 private static JFreeChart createChart() {
   XYDataset xydataset = createDirectionDataset(600);
   JFreeChart jfreechart =
       ChartFactory.createTimeSeriesChart(
           "Time", "Date", "Direction", xydataset, true, true, false);
   XYPlot xyplot = (XYPlot) jfreechart.getPlot();
   xyplot.getDomainAxis().setLowerMargin(0.0D);
   xyplot.getDomainAxis().setUpperMargin(0.0D);
   NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
   numberaxis.setAutoRangeIncludesZero(false);
   TickUnits tickunits = new TickUnits();
   tickunits.add(new NumberTickUnit(180D, new CompassFormat()));
   tickunits.add(new NumberTickUnit(90D, new CompassFormat()));
   tickunits.add(new NumberTickUnit(45D, new CompassFormat()));
   tickunits.add(new NumberTickUnit(22.5D, new CompassFormat()));
   numberaxis.setStandardTickUnits(tickunits);
   xyplot.setRangeAxis(numberaxis);
   XYAreaRenderer xyarearenderer = new XYAreaRenderer();
   NumberAxis numberaxis1 = new NumberAxis("Force");
   numberaxis1.setRange(0.0D, 12D);
   xyarearenderer.setSeriesPaint(0, new Color(0, 0, 255, 128));
   xyplot.setDataset(1, createForceDataset(600));
   xyplot.setRenderer(1, xyarearenderer);
   xyplot.setRangeAxis(1, numberaxis1);
   xyplot.mapDatasetToRangeAxis(1, 1);
   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;
  }
Example #21
0
 private XYPlot getBarPlot() throws KeyedException {
   // use a number axis on the right side with a special formatter for millions
   NumberAxis axis = new NumberAxis();
   axis.setAutoRangeIncludesZero(false);
   axis.setNumberFormatOverride(new NumberFormatForMillions());
   XYPlot plot = new XYPlot(null, null, axis, null);
   plot.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
   return plot;
 }
Example #22
0
 /** Two objects that are equal are required to return the same hashCode. */
 @Test
 public void testHashCode() {
   NumberAxis a1 = new NumberAxis("Test");
   NumberAxis a2 = new NumberAxis("Test");
   assertTrue(a1.equals(a2));
   int h1 = a1.hashCode();
   int h2 = a2.hashCode();
   assertEquals(h1, h2);
 }
  /**
   * Constructs a new demonstration application.
   *
   * @param title the frame title.
   */
  public DynamicDataDemo3(String title) {

    super(title);

    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.datasets = new TimeSeriesCollection[SUBPLOT_COUNT];

    for (int i = 0; i < SUBPLOT_COUNT; i++) {
      this.lastValue[i] = 100.0;
      TimeSeries series = new TimeSeries("Random " + i, Millisecond.class);
      this.datasets[i] = new TimeSeriesCollection(series);
      NumberAxis rangeAxis = new NumberAxis("Y" + i);
      rangeAxis.setAutoRangeIncludesZero(false);
      XYPlot subplot = new XYPlot(this.datasets[i], null, rangeAxis, new StandardXYItemRenderer());
      subplot.setBackgroundPaint(Color.lightGray);
      subplot.setDomainGridlinePaint(Color.white);
      subplot.setRangeGridlinePaint(Color.white);
      plot.add(subplot);
    }

    JFreeChart chart = new JFreeChart("Dynamic Data Demo 3", plot);
    chart.getLegend().setAnchor(Legend.EAST);
    chart.setBorderPaint(Color.black);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds

    JPanel content = new JPanel(new BorderLayout());

    ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    JPanel buttonPanel = new JPanel(new FlowLayout());

    for (int i = 0; i < SUBPLOT_COUNT; i++) {
      JButton button = new JButton("Series " + i);
      button.setActionCommand("ADD_DATA_" + i);
      button.addActionListener(this);
      buttonPanel.add(button);
    }
    JButton buttonAll = new JButton("ALL");
    buttonAll.setActionCommand("ADD_ALL");
    buttonAll.addActionListener(this);
    buttonPanel.add(buttonAll);

    content.add(buttonPanel, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 470));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(content);
  }
 private XYPlot createPlot(BenchmarkReport benchmarkReport, int scoreLevelIndex) {
   Locale locale = benchmarkReport.getLocale();
   NumberAxis xAxis = new NumberAxis("Time spent");
   xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale));
   NumberAxis yAxis = new NumberAxis("Constraint match total weight level " + scoreLevelIndex);
   yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
   yAxis.setAutoRangeIncludesZero(false);
   XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
   plot.setOrientation(PlotOrientation.VERTICAL);
   return plot;
 }
 /**
  * Sets the properties of the specified axis to match the properties defined on this panel.
  *
  * @param axis the axis.
  */
 public void setAxisProperties(Axis axis) {
   super.setAxisProperties(axis);
   NumberAxis numberAxis = (NumberAxis) axis;
   numberAxis.setAutoRange(this.autoRange);
   if (!this.autoRange) {
     numberAxis.setRange(this.minimumValue, this.maximumValue);
   }
   //        numberAxis.setGridLinesVisible(this.showGridLinesCheckBox.isSelected());
   //        numberAxis.setGridPaint(this.gridPaintSample.getPaint());
   //        numberAxis.setGridStroke(this.gridStrokeSample.getStroke());
 }
  /**
   * Update background, tick and gridline colors
   *
   * @param cfg cfg[0] Background, cfg[1] Chart background, cfg[2] y cfg[3] gridline
   */
  public void updateChartColors(String[] cfg) {
    strBackgroundColor = cfg[0];
    for (Node le : legendFrame.getChildren()) {
      if (le instanceof LegendAxis) {
        le.setStyle("-fx-background-color:" + strBackgroundColor);
        ((LegendAxis) le).selected = false;
      }
    }
    chart.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)));
    chartPanel.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(
                scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)))));
    chartPanel.setBackground(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)));

    legendFrame.setStyle("marco: " + strBackgroundColor + ";-fx-background-color: marco;");

    strChartBackgroundColor = cfg[1];
    ;
    plot.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strChartBackgroundColor)));

    for (Node le : legendFrame.getChildren()) {
      if (le instanceof LegendAxis) {
        le.setStyle("-fx-background-color:" + strBackgroundColor);
        ((LegendAxis) le).selected = false;
        for (Node nn : ((LegendAxis) le).getChildren()) {
          if (nn instanceof Label) {
            ((Label) nn)
                .setStyle(
                    "fondo: "
                        + strChartBackgroundColor
                        + ";-fx-background-color: fondo;-fx-text-fill: ladder(fondo, white 49%, black 50%);-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: "
                        + String.valueOf(fontSize)
                        + "px");
          }
        }
      }
    }

    strGridlineColor = cfg[2];
    ;
    plot.setDomainGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor)));
    plot.setRangeGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor)));

    strTickColor = cfg[3];
    ;
    abcissaAxis.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    abcissaAxis.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    for (NumberAxis ejeOrdenada : AxesList) {
      ejeOrdenada.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
      ejeOrdenada.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    }
  }
 private CategoryPlot createBarChartPlot(
     DefaultCategoryDataset dataset, String yAxisLabel, NumberFormat yAxisNumberFormat) {
   CategoryAxis xAxis = new CategoryAxis("Data");
   xAxis.setCategoryMargin(0.40);
   NumberAxis yAxis = new NumberAxis(yAxisLabel);
   yAxis.setNumberFormatOverride(yAxisNumberFormat);
   BarRenderer renderer = createBarChartRenderer(yAxisNumberFormat);
   CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
   plot.setOrientation(PlotOrientation.VERTICAL);
   return plot;
 }
Example #28
0
 /**
  * A simple test for the auto-range calculation looking at a NumberAxis used as the range axis for
  * a CategoryPlot.
  */
 @Test
 public void testAutoRange1() {
   DefaultCategoryDataset dataset = new DefaultCategoryDataset();
   dataset.setValue(100.0, "Row 1", "Column 1");
   dataset.setValue(200.0, "Row 1", "Column 2");
   JFreeChart chart = ChartFactory.createBarChart("Test", "Categories", "Value", dataset);
   CategoryPlot plot = (CategoryPlot) chart.getPlot();
   NumberAxis axis = (NumberAxis) plot.getRangeAxis();
   assertEquals(axis.getLowerBound(), 0.0, EPSILON);
   assertEquals(axis.getUpperBound(), 210.0, EPSILON);
 }
 /**
  * Set the axis range.
  *
  * @param axis a numberAxis
  * @param range a range
  */
 private void setAxisRange(NumberAxis axis, double[] range) {
   if (range == null || range.length != 2) {
     axis.setAutoRange(true);
   } else {
     double lower = range[0];
     double upper = range[1];
     ArgumentNotValid.checkTrue(lower < upper, "Incorrect range");
     axis.setAutoRange(false);
     axis.setRange(new Range(lower, upper));
   }
 }
Example #30
0
  private JFreeChart createChart(
      final String title, final String xAxis, final String yAxis, final XYDataset dataset) {
    final JFreeChart chart =
        ChartFactory.createXYLineChart(
            title, xAxis, yAxis, dataset, PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(Color.white);
    final XYPlot plot = chart.getXYPlot();
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return chart;
  }