コード例 #1
0
  /**
   * This method renders a line chart of income and expense entries over 1-month intervals
   *
   * @param dataset
   * @return financesLineChart_PNL
   */
  private ChartPanel renderLineChart(XYDataset dataset) {

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

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

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

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

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

    return financesLineChart_PNL;
  }
コード例 #2
0
ファイル: ImageHistPanel.java プロジェクト: rforge/timpgui
  private void jButton2ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton2ActionPerformed
    double newMinLifetime, newMaxLifetime;
    try {
      newMinLifetime = Double.parseDouble(jTFMinValue.getText());
      newMaxLifetime = Double.parseDouble(jTFMaxValue.getText());

      IntensImageDataset dataValuesDataset =
          new IntensImageDataset(imHeight, imWidth, new double[imWidth * imHeight]);
      for (int i = 0; i < dataValues.length; i++) {
        dataValuesDataset.SetValue(selImInd[i], dataValues[i]);
      }
      PaintScale ps = new RainbowPaintScale(newMinLifetime, newMaxLifetime);
      JFreeChart aveLifetimeChart =
          createScatChart(
              ImageUtilities.createColorCodedImage(dataValuesDataset, ps), ps, imWidth, imHeight);
      aveLifetimeChart.getXYPlot().getRangeAxis().setInverted(true);
      ChartPanel aveLifetimePanel = new ChartPanel(aveLifetimeChart);
      aveLifetimePanel.setFillZoomRectangle(true);
      aveLifetimePanel.setMouseWheelEnabled(true);
      jPImage.removeAll();
      aveLifetimePanel.setSize(jPImage.getSize());
      aveLifetimePanel.addChartMouseListener(listener);
      jPImage.add(aveLifetimePanel);
      jPImage.repaint();
    } catch (NumberFormatException ex) {
      CoreErrorMessages.selCorrChNum();
    }
  } // GEN-LAST:event_jButton2ActionPerformed
コード例 #3
0
  /**
   * 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;
  }
コード例 #4
0
ファイル: ImageHistPanel.java プロジェクト: rforge/timpgui
 private void jButton5ActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton5ActionPerformed
   int newNumChHish;
   try {
     newNumChHish = Integer.parseInt(jTFChNumHist.getText());
     jPHist.removeAll();
     ChartPanel chpanHist = updateHistPanel(dataValues, minValue, maxValue, newNumChHish);
     chpanHist.setSize(jPHist.getSize());
     jPHist.add(chpanHist);
     jPHist.repaint();
   } catch (NumberFormatException ex) {
     CoreErrorMessages.selCorrChNum();
   }
 } // GEN-LAST:event_jButton5ActionPerformed
コード例 #5
0
  public GenericScatterGraph(XYSeries series, String xAxis, String yAxis) {
    super();

    XYDataset xyDataset = new XYSeriesCollection(series);

    JFreeChart chart =
        ChartFactory.createScatterPlot(
            "", // chart title
            xAxis, // x axis label
            yAxis, // y axis label
            null,
            PlotOrientation.VERTICAL,
            false, // include legend
            true, // tooltips
            false // urls
            );

    chart.setBackgroundPaint(Color.darkGray);
    plot = chart.getXYPlot();
    plot.setDataset(0, xyDataset);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    // Shape cross = ShapeUtilities.createDiamond(0.5f);
    Shape cross = ShapeUtilities.createDiagonalCross(0.5f, 0.5f);
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, new Color(252, 141, 89));
    renderer.setSeriesShape(0, cross);

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickLabelPaint(Color.white);
    domainAxis.setLabelPaint(Color.white);

    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setTickLabelPaint(Color.white);
    rangeAxis.setLabelPaint(Color.white);

    chartPanel = new ChartPanel(chart);
    chartPanel.setSize(100, 800);

    setLayout(new BorderLayout());
    add(chartPanel, BorderLayout.CENTER);
    setBackground(Color.black);

    chartPanel.revalidate();
    setVisible(true);
  }