/**
   * **************************************************************************************** Test
   * for LineChart
   *
   * @throws ChartDataException
   *     ****************************************************************************************
   */
  DataSeries getDataSeries() throws ChartDataException {
    int dataSize = (int) TestDataGenerator.getRandomNumber(2, 25);
    int numberOfDataSets = 1;

    DataSeries dataSeries = super.createDataSeries(dataSize);
    StockChartDataSet stockChartDataSet;

    double[] highs = TestDataGenerator.getRandomNumbers(dataSize, 500, 1000);
    double[] lows = TestDataGenerator.getRandomNumbers(dataSize, 100, 300);
    double[] opens = TestDataGenerator.getRandomNumbers(dataSize, 350, 450);
    double[] closes = TestDataGenerator.getRandomNumbers(dataSize, 350, 450);

    StockChartProperties stockChartProperties = new StockChartProperties();

    stockChartDataSet =
        new StockChartDataSet(highs, "High", lows, "Low", Color.black, stockChartProperties);
    stockChartDataSet.setOpenValues(opens, "Open", Color.red);
    stockChartDataSet.setCloseValues(closes, "Close", Color.green);

    String[] legendLabels = TestDataGenerator.getRandomStrings(numberOfDataSets, 10, false);
    Paint[] paints = TestDataGenerator.getRandomPaints(numberOfDataSets);

    dataSeries.addIAxisPlotDataSet(stockChartDataSet);

    return dataSeries;
  }
Beispiel #2
0
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    try {
      // From AxisChartServlet.java:init()
      LegendProperties legendProperties = new LegendProperties();
      ChartProperties chartProperties = new ChartProperties();
      AxisProperties axisProperties = new AxisProperties(false);

      ChartFont axisScaleFont =
          new ChartFont(new Font("Georgia Negreta cursiva", Font.PLAIN, 13), Color.black);
      axisProperties.getXAxisProperties().setScaleChartFont(axisScaleFont);
      axisProperties.getYAxisProperties().setScaleChartFont(axisScaleFont);

      ChartFont axisTitleFont =
          new ChartFont(new Font("Arial Narrow", Font.PLAIN, 14), Color.black);
      axisProperties.getXAxisProperties().setTitleChartFont(axisTitleFont);
      axisProperties.getYAxisProperties().setTitleChartFont(axisTitleFont);

      Stroke[] strokes = {
        LineChartProperties.DEFAULT_LINE_STROKE,
        LineChartProperties.DEFAULT_LINE_STROKE,
        LineChartProperties.DEFAULT_LINE_STROKE
      };
      Shape[] shapes = {
        PointChartProperties.SHAPE_TRIANGLE,
        PointChartProperties.SHAPE_DIAMOND,
        PointChartProperties.SHAPE_CIRCLE
      };
      LineChartProperties lineChartProperties = new LineChartProperties(strokes, shapes);

      String[] xAxisLabels = {"1998", "1999", "2000", "2001", "2002", "2003", "2004"};
      String xAxisTitle = "Years";
      String yAxisTitle = "Problems";
      String title = "Micro$oft At Work";
      DataSeries dataSeries = new DataSeries(xAxisLabels, xAxisTitle, yAxisTitle, title);

      // From AxisChartServlet.java:createAxisChartDataSet
      double[][] data = TestDataGenerator.getRandomNumbers(3, 7, 200, 500);
      String[] legendLabels = {"Bugs", "Security Holes", "Backdoors"};
      Paint[] paints = TestDataGenerator.getRandomPaints(3);
      AxisChartDataSet acds =
          new AxisChartDataSet(data, legendLabels, paints, ChartType.LINE, lineChartProperties);
      dataSeries.addIAxisPlotDataSet(acds);
      AxisChart axisChart =
          new AxisChart(dataSeries, chartProperties, axisProperties, legendProperties, 550, 360);

      ServletEncoderHelper.encodeJPEG13(axisChart, 1.0f, response);

    } catch (Exception e) {
      System.out.println(e);
    }
  }