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;
  }
Пример #2
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;
  }
Пример #3
0
package com.xuyuan.chart.jfreechart.helloworld;
  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 JFreeChart createChart() {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createXYLineChart(
            null, // chart title
            null, // x axis label
            null, // y axis label
            null, // data
            PlotOrientation.VERTICAL,
            false, // include legend
            true, // tooltips
            false // urls
            );

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customization...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // domain axis

    if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) {
      if ((dataTable.isDate(indexAxis)) || (dataTable.isDateTime(indexAxis))) {
        DateAxis domainAxis = new DateAxis(dataTable.getColumnName(indexAxis));
        domainAxis.setTimeZone(Tools.getPreferredTimeZone());
        chart.getXYPlot().setDomainAxis(domainAxis);
      }
    } else {
      plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US));
      ((NumberAxis) plot.getDomainAxis()).setAutoRangeStickyZero(false);
      ((NumberAxis) plot.getDomainAxis()).setAutoRangeIncludesZero(false);
    }
    ValueAxis xAxis = plot.getDomainAxis();
    if (indexAxis > -1) xAxis.setLabel(getDataTable().getColumnName(indexAxis));
    else xAxis.setLabel(SERIESINDEX_LABEL);
    xAxis.setAutoRange(true);
    xAxis.setLabelFont(LABEL_FONT_BOLD);
    xAxis.setTickLabelFont(LABEL_FONT);
    xAxis.setVerticalTickLabels(isLabelRotating());
    if (indexAxis > 0) {
      if (getRangeForDimension(indexAxis) != null) {
        xAxis.setRange(getRangeForDimension(indexAxis));
      }
    } else {
      if (getRangeForName(SERIESINDEX_LABEL) != null) {
        xAxis.setRange(getRangeForName(SERIESINDEX_LABEL));
      }
    }

    // renderer and range axis
    synchronized (dataTable) {
      int numberOfSelectedColumns = 0;
      for (int c = 0; c < dataTable.getNumberOfColumns(); c++) {
        if (getPlotColumn(c)) {
          if (dataTable.isNumerical(c)) {
            numberOfSelectedColumns++;
          }
        }
      }

      int columnCount = 0;
      for (int c = 0; c < dataTable.getNumberOfColumns(); c++) {
        if (getPlotColumn(c)) {
          if (dataTable.isNumerical(c)) {
            // YIntervalSeries series = new YIntervalSeries(this.dataTable.getColumnName(c));
            XYSeriesCollection dataset = new XYSeriesCollection();
            XYSeries series = new XYSeries(dataTable.getColumnName(c));
            Iterator<DataTableRow> i = dataTable.iterator();
            int index = 1;
            while (i.hasNext()) {
              DataTableRow row = i.next();
              double value = row.getValue(c);

              if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) {
                double indexValue = row.getValue(indexAxis);
                series.add(indexValue, value);
              } else {
                series.add(index++, value);
              }
            }
            dataset.addSeries(series);

            XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

            Color color = getColorProvider().getPointColor(1.0d);
            if (numberOfSelectedColumns > 1) {
              color =
                  getColorProvider()
                      .getPointColor(columnCount / (double) (numberOfSelectedColumns - 1));
            }
            renderer.setSeriesPaint(0, color);
            renderer.setSeriesStroke(
                0, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            renderer.setSeriesShapesVisible(0, false);

            NumberAxis yAxis = new NumberAxis(dataTable.getColumnName(c));
            if (getRangeForDimension(c) != null) {
              yAxis.setRange(getRangeForDimension(c));
            } else {
              yAxis.setAutoRange(true);
              yAxis.setAutoRangeStickyZero(false);
              yAxis.setAutoRangeIncludesZero(false);
            }
            yAxis.setLabelFont(LABEL_FONT_BOLD);
            yAxis.setTickLabelFont(LABEL_FONT);
            if (numberOfSelectedColumns > 1) {
              yAxis.setAxisLinePaint(color);
              yAxis.setTickMarkPaint(color);
              yAxis.setLabelPaint(color);
              yAxis.setTickLabelPaint(color);
            }

            plot.setRangeAxis(columnCount, yAxis);
            plot.setRangeAxisLocation(columnCount, AxisLocation.TOP_OR_LEFT);

            plot.setDataset(columnCount, dataset);
            plot.setRenderer(columnCount, renderer);
            plot.mapDatasetToRangeAxis(columnCount, columnCount);

            columnCount++;
          }
        }
      }
    }

    chart.setBackgroundPaint(Color.white);

    return chart;
  }