Beispiel #1
0
  @Override
  public XYChart getChart() {

    // Create Chart
    XYChart chart = new XYChartBuilder().width(800).height(600).title("Second Scale").build();

    // Customize Chart
    chart.getStyler().setLegendVisible(false);
    chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Area);

    // Series
    List<Date> xData = new ArrayList<Date>();
    List<Double> yData = new ArrayList<Double>();

    Random random = new Random();

    DateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
    Date date = null;
    for (int i = 1; i <= 14; i++) {
      try {
        date = sdf.parse("23:45:" + (5 * i + random.nextInt(2)) + "." + random.nextInt(1000));
      } catch (ParseException e) {
        e.printStackTrace();
      }
      xData.add(date);
      yData.add(Math.random() * i);
    }

    chart.addSeries("blah", xData, yData);

    return chart;
  }
Beispiel #2
0
  @Override
  public XYChart getChart() {

    // Create Chart
    XYChart chart = new XYChartBuilder().width(800).height(600).build();

    // Customize Chart
    chart.getStyler().setChartTitleVisible(false);
    chart.getStyler().setLegendVisible(false);

    // generates sine data
    int size = 30;
    List<Integer> xData = new ArrayList<Integer>();
    List<Double> yData = new ArrayList<Double>();
    for (int i = 0; i <= size; i++) {
      double radians = (Math.PI / (size / 2) * i);
      xData.add(i - size / 2);
      yData.add(-.000001 * Math.sin(radians));
    }

    // generates cos data
    List<Integer> xData2 = new ArrayList<Integer>();
    List<Double> yData2 = new ArrayList<Double>();
    for (int i = 0; i <= size; i++) {
      double radians = (Math.PI / (size / 2) * i);
      xData2.add(i - size / 2);
      yData2.add(-.000001 * Math.cos(radians));
    }

    // Series
    XYSeries series = chart.addSeries("y=sin(x)", xData, yData);
    series.setLineColor(XChartSeriesColors.PURPLE);
    series.setLineStyle(SeriesLines.DASH_DASH);
    series.setMarkerColor(XChartSeriesColors.GREEN);
    series.setMarker(SeriesMarkers.SQUARE);

    series = chart.addSeries("y=cos(x)", xData2, yData2);
    series.setLineColor(XChartSeriesColors.PINK);
    series.setLineWidth(5);
    series.setMarker(SeriesMarkers.NONE);

    return chart;
  }