2013-12-10 111 views

回答

0

我想this link幫助您 - 試試這個教程。它將創建一個簡單的XYPlot

package com.androidplot.demos; 
import android.app.Activity; 
import android.os.Bundle; 
import android.view.WindowManager; 
import com.androidplot.xy.SimpleXYSeries; 
import com.androidplot.xy.XYSeries; 
import com.androidplot.xy.*; 
import java.util.Arrays; 

/** 
* A straightforward example of using AndroidPlot to plot some data. 
*/ 
public class SimpleXYPlotActivity extends Activity 
{ 

    private XYPlot plot; 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 

     // fun little snippet that prevents users from taking screenshots 
     // on ICS+ devices :-) 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, 
           WindowManager.LayoutParams.FLAG_SECURE); 

     setContentView(R.layout.simple_xy_plot_example); 

     // initialize our XYPlot reference: 
     plot = (XYPlot) findViewById(R.id.mySimpleXYPlot); 

     // Create a couple arrays of y-values to plot: 
     Number[] series1Numbers = {1, 8, 5, 2, 7, 4}; 
     Number[] series2Numbers = {4, 6, 3, 8, 2, 10}; 

     // Turn the above arrays into XYSeries': 
     XYSeries series1 = new SimpleXYSeries(
       Arrays.asList(series1Numbers),   // SimpleXYSeries takes a List so turn our array into a List 
       SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Y_VALS_ONLY means use the element index as the x value 
       "Series1");        // Set the display title of the series 

     // same as above 
     XYSeries series2 = new SimpleXYSeries(Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series2"); 

     // Create a formatter to use for drawing a series using LineAndPointRenderer 
     // and configure it from xml: 
     LineAndPointFormatter series1Format = new LineAndPointFormatter(); 
     series1Format.setPointLabelFormatter(new PointLabelFormatter()); 
     series1Format.configure(getApplicationContext(), 
       R.xml.line_point_formatter_with_plf1); 

     // add a new series' to the xyplot: 
     plot.addSeries(series1, series1Format); 

     // same as above: 
     LineAndPointFormatter series2Format = new LineAndPointFormatter(); 
     series2Format.setPointLabelFormatter(new PointLabelFormatter()); 
     series2Format.configure(getApplicationContext(), 
       R.xml.line_point_formatter_with_plf2); 
     plot.addSeries(series2, series2Format); 

     // reduce the number of range labels 
     plot.setTicksPerRangeLabel(3); 
     plot.getGraphWidget().setDomainLabelOrientation(-45); 

    } 
} 
0

嘗試此鏈接:Creating the Area Chart

有一個樣品的程序,它創建一個簡單區域圖表:

爲了創建一個簡單的區域圖表需要創建圖表系列的一個實例 ,設置圖圖表爲Area和下面的示例中填充串聯一些數據, 像:

package com.artfulbits.aiCharts.areasample; 

import com.artfulbits.aiCharts.ChartView; 
import com.artfulbits.aiCharts.Base.*; 

import android.app.Activity; 
import android.os.Bundle; 

public class MainActivity extends Activity 
{ 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     ChartView chartView = (ChartView) findViewById(R.id.chartView); 
     ChartSeries series1 = chartView.getSeries().get("Series1"); 
     ChartSeries series2 = chartView.getSeries().get("Series2"); 
     double[] data1 = { 82, 75, 96, 65, 87 }; 
     double[] data2 = { 37, 28, 43, 48, 56 }; 
     series1.getPoints().setData(data1); 
     series2.getPoints().setData(data2); 
    } 
}