kstanoev
4/7/2014 - 8:27 AM

Creating a RadChart

Creating a RadChart

private RadCartesianChartView createChart(Iterable<SeismicDataPoint> dataPoints) {
    RadCartesianChartView chart = new RadCartesianChartView(this);
 
    LineSeries series = new LineSeries(this);
    // create category binding with the X coordinate of the accelerometer point
    DataPointBinding categoryBinding = new DataPointBinding() {
        @Override
        public Object getValue(Object o) throws IllegalArgumentException {
            return ((SeismicDataPoint) o).x;
        }
    };
    series.setCategoryBinding(categoryBinding);
 
    // create value binding with the Y coordinate of the accelerometer point
    DataPointBinding valueBinding = new DataPointBinding() {
        @Override
        public Object getValue(Object o) throws IllegalArgumentException {
            return ((SeismicDataPoint) o).y;
        }
    };
    series.setValueBinding(valueBinding);
    chart.getSeries().add(series);
 
    // feed the data to the chart
    series.setData(dataPoints);
 
    // configure the vertical axis
    LinearAxis vAxis = new LinearAxis(this);
    // The maximum value of the accelerometer is 20 and the minimum -20, so give a bonus 10 to the vertical axis.
    vAxis.setMaximum(30);
    vAxis.setMinimum(-30);
    chart.setVerticalAxis(vAxis);
 
    // configure the horizontal axis
    CategoricalAxis hAxis = new CategoricalAxis(this);
    hAxis.setShowLabels(false);
    chart.setHorizontalAxis(hAxis);
 
    return chart;
}