Exemplo n.º 1
0
 public GraphView refreshGraph(double[] values) {
   GraphViewData[] data = new GraphViewData[Globals.NUMBER_DATA];
   for (int i = 0; i < Globals.NUMBER_DATA; i++) {
     data[i] = new GraphViewData((i * Globals.FACTOR_MULTIPLY), values[i]);
   }
   graphView = new LineGraphView(mContext, mContext.getString(R.string.titleGraph));
   graphView.addSeries(new GraphViewSeries(data));
   graphView.setViewPort(Globals.X_AXYS_MIN, Globals.X_AXYS_MAX);
   graphView.setScrollable(true);
   graphView.setScalable(true);
   return graphView;
 }
Exemplo n.º 2
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.graphs);

    // init example series data
    exampleSeries1 =
        new GraphViewSeries(
            new GraphViewData[] {
              new GraphViewData(1, 2.0d),
              new GraphViewData(2, 1.5d),
              new GraphViewData(2.5, 3.0d) // another frequency
              ,
              new GraphViewData(3, 2.5d),
              new GraphViewData(4, 1.0d),
              new GraphViewData(5, 3.0d)
            });

    // graph with dynamically genereated horizontal and vertical labels
    if (getIntent().getStringExtra("type").equals("bar")) {
      graphView =
          new BarGraphView(
              this // context
              ,
              "GraphViewDemo" // heading
              );
    } else {
      graphView =
          new LineGraphView(
              this // context
              ,
              "GraphViewDemo" // heading
              );
    }
    graphView.addSeries(exampleSeries1); // data

    LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
    layout.addView(graphView);

    // ----------
    exampleSeries2 =
        new GraphViewSeries(
            new GraphViewData[] {
              new GraphViewData(1, 2.0d),
              new GraphViewData(2, 1.5d),
              new GraphViewData(2.5, 3.0d) // another frequency
              ,
              new GraphViewData(3, 2.5d),
              new GraphViewData(4, 1.0d),
              new GraphViewData(5, 3.0d)
            });

    // graph with custom labels and drawBackground
    if (getIntent().getStringExtra("type").equals("bar")) {
      graphView = new BarGraphView(this, "GraphViewDemo");
    } else {
      graphView = new LineGraphView(this, "GraphViewDemo");
      ((LineGraphView) graphView).setDrawBackground(true);
    }
    graphView.addSeries(exampleSeries2); // data
    graphView.setViewPort(1, 4);
    graphView.setScalable(true);

    layout = (LinearLayout) findViewById(R.id.graph2);
    layout.addView(graphView);
  }