public static void updateChart() {
   if (iobcobPastChart != null) {
     iobcobPastChart.setLineChartData(
         LineChartData
             .generateDummyData()); //// TODO: 07/10/2015 debug, trying to reset data in chart to
                                    // stop odd issue with lines looping
     iobcobPastChart.setLineChartData(extendedGraphBuilder.iobcobPastLineData());
   }
 }
  private void generateInitialLineData() {
    int numValues = 7;
    List<AxisValue> axisValues = new ArrayList<AxisValue>();
    List<PointValue> values = new ArrayList<PointValue>();
    for (int i = 0; i < numValues; ++i) {
      values.add(new PointValue(i, 0));
      axisValues.add(new AxisValue(i).setLabel(days[i]));
    }
    Line line = new Line(values);
    line.setColor(ChartUtils.COLOR_GREEN).setCubic(true);
    List<Line> lines = new ArrayList<Line>();
    lines.add(line);
    lineData = new LineChartData(lines);
    lineData.setAxisXBottom(new Axis(axisValues).setHasLines(true));
    lineData.setAxisYLeft(new Axis().setHasLines(true).setMaxLabelChars(3));
    chartTop.setLineChartData(lineData);
    // For build-up animation you have to disable viewport recalculation.
    chartTop.setViewportCalculationEnabled(false);

    // And set initial max viewport and current viewport- remember to set viewports after data.
    Viewport v = new Viewport(0, 110, 6, 0);
    chartTop.setMaximumViewport(v);
    chartTop.setCurrentViewport(v);

    chartTop.setZoomType(ZoomType.HORIZONTAL);
    generateLineData(ChartUtils.COLOR_GREEN, 100);
  }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   int id = item.getItemId();
   if (id == R.id.action_reset) {
     getForecastData();
     chart.setLineChartData(data);
     previewChart.setLineChartData(previewData);
     previewX(true);
     return true;
   }
   if (id == R.id.action_preview_both) {
     previewXY();
     previewChart.setZoomType(ZoomType.HORIZONTAL_AND_VERTICAL);
     return true;
   }
   if (id == R.id.action_preview_horizontal) {
     previewX(true);
     return true;
   }
   if (id == R.id.action_preview_vertical) {
     previewY();
     return true;
   }
   if (id == R.id.action_change_color) {
     int color = ChartUtils.pickColor();
     while (color == previewChart.getPreviewColor()) {
       color = ChartUtils.pickColor();
     }
     previewChart.setPreviewColor(color);
     return true;
   }
   return super.onOptionsItemSelected(item);
 }
    // 产生数据 实时
    /////////////////////////////////////////////////////////////////////////////////////////
    private void generateInitialLineData() {
      int numValues = 19;

      List<AxisValue> axisValues = new ArrayList<AxisValue>();
      List<PointValue> values = new ArrayList<PointValue>();
      for (int i = 0; i < numValues; ++i) {
        values.add(new PointValue(i, 0));
        axisValues.add(new AxisValue(i).setLabel(days[i]));
      }

      Line line = new Line(values);
      line.setColor(ChartUtils.COLOR_BLUE);
      line.setHasPoints(false);
      line.getShape();
      line.setCubic(false); // 平滑

      List<Line> lines = new ArrayList<Line>();
      lines.add(line);
      //            lines.add(line1);
      //            lines.add(line2);

      Axis axisX = new Axis(axisValues);
      Axis axisY = new Axis().setHasLines(true);
      if (hasAxesNames) {
        axisX.setName("时间间隔");
        // axisY.setName("温度");
        axisX.setTextColor(ChartUtils.HOLO_BLUE_DARK);
        axisY.setTextColor(ChartUtils.HOLO_BLUE_DARK);
      }

      lineData = new LineChartData(lines);
      lineData.setAxisXBottom(axisX.setHasLines(true));
      lineData.setAxisYLeft(axisY.setMaxLabelChars(4));

      realeChartTop.setLineChartData(lineData);

      // For build-up animation you have to disable viewport recalculation.
      // 建立动画你必须禁用视图重新计算。
      realeChartTop.setViewportCalculationEnabled(false);

      // And set initial max viewport and current viewport- remember to set viewports after data.
      // 设置初始值和当前视口视口记得要在数据集视图。
      Viewport v = new Viewport(0, 50, 20, -10);
      realeChartTop.setMaximumViewport(v);
      realeChartTop.setCurrentViewport(v);
      realeChartTop.setZoomType(ZoomType.HORIZONTAL);

      // toggleFilled();
      // toggleLabels();
      toggleAxesNames();
    }
    private void showRecoedData(int[] recordMsgBuffer) {
      generateDefaultData(recordMsgBuffer);

      //            Viewport maxV=recordChart.getMaximumViewport();
      //            recordChart.setMaximumViewport(new Viewport(maxV.left, 100, maxV.right, 0));

      recordChart.setLineChartData(data);
      recordChart.setZoomEnabled(false);
      recordChart.setScrollEnabled(false);

      recordPreviewChart.setLineChartData(previewData);

      recordPreviewChart.setViewportChangeListener(new ViewportListener());

      previewX(false);

      disRecordHideReal();
    }
  public void setupCharts() {
    if (bgDataList.size()
        > 0) { // Dont crash things just because we dont have values, people dont like crashy things
      if (singleLine) {
        bgGraphBuilder =
            new BgGraphBuilder(getApplicationContext(), bgDataList, pointSize, midColor);
      } else {
        bgGraphBuilder =
            new BgGraphBuilder(
                getApplicationContext(), bgDataList, pointSize, highColor, lowColor, midColor);
      }

      chart.setLineChartData(bgGraphBuilder.lineData());
      chart.setViewportCalculationEnabled(true);
      chart.setMaximumViewport(chart.getMaximumViewport());
    } else {
      ListenerService.requestData(this);
    }
  }
  public void addListToChart(List<Day> days) {
    int currentValue;
    int size = days.size();
    maxValueOfLineChartData = 0;
    List<PointValue> valuePoints = new ArrayList<PointValue>();

    if (size == 1) {
      for (int i = 0; i < 24; i++) {
        currentValue = days.get(0).getHours().get(i).getMmm().getMean();
        if (currentValue > maxValueOfLineChartData) {
          maxValueOfLineChartData = currentValue;
        }
        valuePoints.add(new PointValue(i, currentValue));
      }
    } else {
      for (int i = 0; i < size; i++) {
        currentValue = days.get(i).getMmm().getMean();
        if (currentValue > maxValueOfLineChartData) {
          maxValueOfLineChartData = currentValue;
        }
        valuePoints.add(new PointValue(i, currentValue));
      }
    }

    dataLine = new Line(valuePoints);
    dataLine.setColor(ChartUtils.COLOR_ORANGE);
    dataLine.setHasPoints(false);

    List<Line> lines = new ArrayList<Line>();
    lines.add(dataLine);

    data = new LineChartData(lines);
    data.setAxisXBottom(new Axis());
    data.setAxisYLeft(new Axis().setHasLines(true));

    previewData = new LineChartData(data);
    previewData.getLines().get(0).setColor(ChartUtils.DEFAULT_DARKEN_COLOR);

    chart.setLineChartData(data);
    previewChart.setLineChartData(previewData);

    updateChartView();
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment

    setHasOptionsMenu(true);
    View rootView = inflater.inflate(R.layout.fragment_temperature, container, false);

    chart = (LineChartView) rootView.findViewById(R.id.chart);
    previewChart = (PreviewLineChartView) rootView.findViewById(R.id.chart_preview);

    // Generate data for previewed chart and copy of that data for preview chart.

    if (getArguments() != null) {
      temperatureData = getArguments();
      latitude = temperatureData.getFloat("latitude");
      longitude = temperatureData.getFloat("longitude");
      temperatures = temperatureData.getDoubleArray("temperatureArr");
      times = temperatureData.getIntArray("timeArr");
      numData = temperatureData.getInt("numData");
      Log.d("ARRAY", Arrays.toString(temperatures));
      Log.d("ARRAY", Arrays.toString(times));
      getForecastData();

      Log.d("receiver", "OK");
    } else {
      generateDefaultData();
    }
    chart.setLineChartData(data);
    // Disable zoom/scroll for previewed chart, visible chart ranges depends on preview chart
    // viewport so
    // zoom/scroll is unnecessary.
    chart.setZoomEnabled(false);
    chart.setScrollEnabled(false);

    previewChart.setLineChartData(previewData);
    previewChart.setViewportChangeListener(new ViewportListener());

    previewX(false);

    return rootView;
  }
    public void setupChart() {
      basalvsTempBasalChart.setZoomType(ZoomType.HORIZONTAL);
      basalvsTempBasalChart.setLineChartData(extendedGraphBuilder.basalvsTempBasalData());

      Viewport iobv =
          new Viewport(
              basalvsTempBasalChart
                  .getMaximumViewport()); // Sets the min and max for Top and Bottom of the
                                          // viewpoint
      iobv.top = extendedGraphBuilder.maxBasal.floatValue();
      iobv.bottom = -(extendedGraphBuilder.maxBasal.floatValue() - 1);
      basalvsTempBasalChart.setMaximumViewport(iobv);
      iobv.left = previewChart.getCurrentViewport().left;
      iobv.right = previewChart.getCurrentViewport().right;
      basalvsTempBasalChart.setCurrentViewport(iobv);

      basalvsTempBasalChart.setViewportCalculationEnabled(true);
      // iobcobPastChart.setViewportChangeListener(new ChartViewPortListener());
      // //causes a crash, no idea why #// TODO: 28/08/2015
    }
    public void setupChart() {

      iobcobPastChart.setZoomType(ZoomType.HORIZONTAL);
      iobcobPastChart.setLineChartData(extendedGraphBuilder.iobcobPastLineData());

      Viewport iobv =
          new Viewport(
              iobcobPastChart
                  .getMaximumViewport()); // Sets the min and max for Top and Bottom of the
                                          // viewpoint
      iobv.top = Float.parseFloat(extendedGraphBuilder.yCOBMax.toString());
      iobv.bottom = Float.parseFloat(extendedGraphBuilder.yCOBMin.toString());
      iobcobPastChart.setMaximumViewport(iobv);
      iobv.left = previewChart.getCurrentViewport().left;
      iobv.right = previewChart.getCurrentViewport().right;
      iobcobPastChart.setCurrentViewport(iobv);

      iobcobPastChart.setViewportCalculationEnabled(true);
      // iobcobPastChart.setViewportChangeListener(new ChartViewPortListener());
      // //causes a crash, no idea why #// TODO: 28/08/2015
    }
  public void setupCharts() {

    // BG charts
    updateStuff = false;
    chart = (LineChartView) findViewById(R.id.chart);
    chart.setZoomType(ZoomType.HORIZONTAL);

    previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview);
    previewChart.setZoomType(ZoomType.HORIZONTAL);

    chart.setLineChartData(extendedGraphBuilder.lineData());
    previewChart.setLineChartData(extendedGraphBuilder.previewLineData());
    updateStuff = true;

    previewChart.setViewportCalculationEnabled(true);
    chart.setViewportCalculationEnabled(true);
    previewChart.setViewportChangeListener(new ViewportListener());
    chart.setViewportChangeListener(new ChartViewPortListener());

    setViewport();
  }
  @Override
  public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    chart = (LineChartView) view.findViewById(R.id.chart);
    chart.setLineChartData(data);
    chart.setZoomEnabled(true);
    chart.setScrollEnabled(true);

    previewChart = (PreviewLineChartView) view.findViewById(R.id.chart_preview);
    previewChart.setLineChartData(previewData);
    previewChart.setViewportChangeListener(new ViewportListener());

    final Button selectButton = (Button) view.findViewById(R.id.button_left);
    selectButton.setText(selectString[userChoice]);
    selectButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (dialogSelect == null) {
              dialogSelect = new Dialog(v.getContext());
            }

            dialogSelect.setContentView(R.layout.dialog_select);
            dialogSelect.setTitle(dialogSelectPeriodTitle);

            numberPicker = (NumberPicker) dialogSelect.findViewById(R.id.number_picker);
            numberPicker.setMinValue(0);
            numberPicker.setMaxValue(selectString.length - 1);
            numberPicker.setDisplayedValues(selectString);
            numberPicker.setWrapSelectorWheel(true);

            Button dialogButton = (Button) dialogSelect.findViewById(R.id.apply_button_select);
            dialogButton.setOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    userChoice = numberPicker.getValue();
                    selectButton.setText(selectString[userChoice]);
                    dialogSelect.dismiss();
                    dateButton.callOnClick();
                  }
                });

            dialogSelect.show();
          }
        });

    dateButton = (Button) view.findViewById(R.id.button_right);
    if (pickedCalendar == null) {
      dateButton.setText("Datum");
    } else {
      setDateButtonText();
    }
    dateButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (dialog == null) {
              dialog = new Dialog(v.getContext());
            }
            switch (userChoice) {
              case DAY:
              case WEEK:
                dialog.setContentView(R.layout.dialog);
                datePicker = (DatePicker) dialog.findViewById(R.id.dpResult);
                break;
              case MONTH:
                dialog.setContentView(R.layout.dialog_month);
                monthPicker = (NumberPicker) dialog.findViewById(R.id.picker_month_month);
                monthPicker.setMinValue(0);
                monthPicker.setMaxValue(11);
                monthPicker.setDisplayedValues(monthString);
                monthPicker.setWrapSelectorWheel(true);
                yearPicker = (NumberPicker) dialog.findViewById(R.id.picker_month_year);
                yearPicker.setMinValue(2015);
                yearPicker.setMaxValue(2100);
                yearPicker.setWrapSelectorWheel(true);
                break;
              case YEAR:
                dialog.setContentView(R.layout.dialog_year);
                yearPicker = (NumberPicker) dialog.findViewById(R.id.picker_year_year);
                yearPicker.setMinValue(2015);
                yearPicker.setMaxValue(2100);
                yearPicker.setWrapSelectorWheel(true);
                break;
            }
            dialog.setTitle(dialogSelectDateTilte);

            Button dialogButton = (Button) dialog.findViewById(R.id.apply_button);
            dialogButton.setOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    setPickedDate();
                    handleUserChoice();
                    updateChartView();
                    dialog.dismiss();
                  }
                });

            dialog.show();
          }
        });
    updateChartView();
  }
  private void updateGraph(Cursor cursor) {
    // set up the goal line
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    int goalCalories = Integer.parseInt(prefs.getString("preference_calorie_goal", "2000"));
    List<PointValue> goalValues = new ArrayList<>();

    // set up the data
    List<PointValue> values = new ArrayList<>();
    cursor.moveToFirst();

    if (!cursor.isAfterLast()) {
      goalValues.add(new PointValue(getTimeFromRow(cursor), goalCalories));
    }

    while (cursor.isAfterLast() == false) {
      float value = cursor.getFloat(cursor.getColumnIndex("total"));
      // Log.d("graph", "adding " + value + " on " + sdf.format(getTimeFromRow(cursor)));
      values.add(new PointValue(getTimeFromRow(cursor), value));
      cursor.moveToNext();
    }

    cursor.moveToLast();
    goalValues.add(new PointValue(getTimeFromRow(cursor), goalCalories));

    List<Line> lines = new ArrayList<Line>();

    Line goalLine = new Line(goalValues).setColor(Color.parseColor("#ff0000"));
    lines.add(goalLine);

    Line line = new Line(values).setColor(Color.parseColor("#44a134")).setCubic(true);
    // line.setFilled(true);
    // line.setHasLabels(true);

    lines.add(line);

    LineChartData data = new LineChartData();
    data.setLines(lines);

    Axis timeAxis = new Axis();
    // timeAxis.setName("");
    // timeAxis.setTextColor(ChartUtils.COLOR_ORANGE);
    timeAxis.setMaxLabelChars(5);
    timeAxis.setFormatter(new TimestampAxisFormatter());
    timeAxis.setHasLines(true);
    timeAxis.setHasTiltedLabels(true);
    data.setAxisXBottom(timeAxis);

    Axis calorieAxis = new Axis();
    // weightAxis.setName("");
    // weightAxis.setTextColor(ChartUtils.COLOR_GREEN);
    calorieAxis.setMaxLabelChars(7);
    calorieAxis.setFormatter(new SimpleAxisValueFormatter().setAppendedText(" C".toCharArray()));
    calorieAxis.setHasLines(true);
    calorieAxis.setHasTiltedLabels(true);
    data.setAxisYLeft(calorieAxis);

    hellochart.setLineChartData(data);
    hellochart.setZoomType(ZoomType.HORIZONTAL);
    hellochart.setOnValueTouchListener(new ValueTouchListener());

    // set up zoom so we can see 0 calories
    Viewport viewport = new Viewport(hellochart.getMaximumViewport());
    viewport.bottom = 0;
    hellochart.setMaximumViewport(viewport);
    hellochart.setCurrentViewport(viewport);

    hellochart.invalidate();
  }
    @Override
    public View onCreateView(
        LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_view_pager_charts, container, false);
      RelativeLayout layout = (RelativeLayout) rootView;
      int sectionNum = getArguments().getInt(ARG_SECTION_NUMBER);
      switch (sectionNum) {
        case 1:
          LineChartView lineChartView = new LineChartView(getActivity());
          lineChartView.setLineChartData(generateLineChartData());
          lineChartView.setZoomType(ZoomType.HORIZONTAL);

          /** Note: Chart is within ViewPager so enable container scroll mode. * */
          lineChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

          layout.addView(lineChartView);
          break;
        case 2:
          ColumnChartView columnChartView = new ColumnChartView(getActivity());
          columnChartView.setColumnChartData(generateColumnChartData());
          columnChartView.setZoomType(ZoomType.HORIZONTAL);

          /** Note: Chart is within ViewPager so enable container scroll mode. * */
          columnChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

          layout.addView(columnChartView);
          break;
        case 3:
          BubbleChartView bubbleChartView = new BubbleChartView(getActivity());
          bubbleChartView.setBubbleChartData(generateBubbleChartData());
          bubbleChartView.setZoomType(ZoomType.HORIZONTAL_AND_VERTICAL);

          /** Note: Chart is within ViewPager so enable container scroll mode. * */
          bubbleChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

          layout.addView(bubbleChartView);
          break;
        case 4:
          PreviewLineChartView previewLineChartView = new PreviewLineChartView(getActivity());
          previewLineChartView.setLineChartData(generatePreviewLineChartData());

          /** Note: Chart is within ViewPager so enable container scroll mode. * */
          previewLineChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

          Viewport tempViewport = new Viewport(previewLineChartView.getMaximumViewport());
          float dx = tempViewport.width() / 6;
          tempViewport.inset(dx, 0);
          previewLineChartView.setCurrentViewport(tempViewport);
          previewLineChartView.setZoomType(ZoomType.HORIZONTAL);

          layout.addView(previewLineChartView);
          break;
        case 5:
          PieChartView pieChartView = new PieChartView(getActivity());
          pieChartView.setPieChartData(generatePieChartData());

          /** Note: Chart is within ViewPager so enable container scroll mode. * */
          pieChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

          layout.addView(pieChartView);
          break;
      }

      return rootView;
    }
 // Updates Stats
 public static void updateChart() {
   if (basalvsTempBasalChart != null) {
     basalvsTempBasalChart.setLineChartData(extendedGraphBuilder.basalvsTempBasalData());
   }
 }
  public void setupCharts() {
    bgGraphBuilder = new BgGraphBuilder(this);
    updateStuff = false;
    chart = (LineChartView) findViewById(R.id.chart);

    if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
      ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) chart.getLayoutParams();
      params.topMargin = 130;
      chart.setLayoutParams(params);
    }

    chart.setZoomType(ZoomType.HORIZONTAL);

    // Transmitter Battery Level
    final Sensor sensor = Sensor.currentSensor();
    if (sensor != null
        && sensor.latest_battery_level != 0
        && sensor.latest_battery_level <= Constants.TRANSMITTER_BATTERY_LOW) {
      Drawable background =
          new Drawable() {

            @Override
            public void draw(Canvas canvas) {

              DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics();
              int px = (int) (30 * (metrics.densityDpi / 160f));
              Paint paint = new Paint();
              paint.setTextSize(px);
              paint.setAntiAlias(true);
              paint.setColor(Color.parseColor("#FFFFAA"));
              paint.setStyle(Paint.Style.STROKE);
              paint.setAlpha(100);
              canvas.drawText(
                  "transmitter battery", 10, chart.getHeight() / 3 - (int) (1.2 * px), paint);
              if (sensor.latest_battery_level <= Constants.TRANSMITTER_BATTERY_EMPTY) {
                paint.setTextSize((int) (px * 1.5));
                canvas.drawText("VERY LOW", 10, chart.getHeight() / 3, paint);
              } else {
                canvas.drawText("low", 10, chart.getHeight() / 3, paint);
              }
            }

            @Override
            public void setAlpha(int alpha) {}

            @Override
            public void setColorFilter(ColorFilter cf) {}

            @Override
            public int getOpacity() {
              return 0;
            }
          };
      chart.setBackground(background);
    }
    previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview);
    previewChart.setZoomType(ZoomType.HORIZONTAL);

    chart.setLineChartData(bgGraphBuilder.lineData());
    previewChart.setLineChartData(bgGraphBuilder.previewLineData());
    updateStuff = true;

    previewChart.setViewportCalculationEnabled(true);
    chart.setViewportCalculationEnabled(true);
    previewChart.setViewportChangeListener(new ViewportListener());
    chart.setViewportChangeListener(new ChartViewPortListener());
    setViewport();
  }
 private void cleanChart() {
   chart.setLineChartData(null);
   previewChart.setLineChartData(null);
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.graph);
    // generate Dates
    Calendar calendar = Calendar.getInstance();
    Date d1 = calendar.getTime();
    calendar.add(Calendar.DATE, 1);
    Date d2 = calendar.getTime();
    calendar.add(Calendar.DATE, 1);
    Date d3 = calendar.getTime();

    Date d4 = calendar.getTime();
    calendar.add(Calendar.DATE, 1);
    Date d5 = calendar.getTime();
    calendar.add(Calendar.DATE, 1);
    Date d6 = calendar.getTime();

    Date d7 = calendar.getTime();
    calendar.add(Calendar.DATE, 1);
    Date d8 = calendar.getTime();
    calendar.add(Calendar.DATE, 1);
    Date d9 = calendar.getTime();

    GraphView graph = (GraphView) findViewById(R.id.graph);

    // you can directly pass Date objects to DataPoint-Constructor
    // this will convert the Date to double via Date#getTime()
    LineGraphSeries<DataPoint> series =
        new LineGraphSeries<DataPoint>(
            new DataPoint[] {
              new DataPoint(d1, 1),
              new DataPoint(d2, 5),
              new DataPoint(d3, 3),
              new DataPoint(d4, 4),
              new DataPoint(d5, 6),
              new DataPoint(d6, 5),
              new DataPoint(d7, 7),
              new DataPoint(d8, 4),
              new DataPoint(d9, 6),
            });
    series.setColor(getResources().getColor(android.R.color.holo_green_dark));
    LineGraphSeries<DataPoint> series2 =
        new LineGraphSeries<DataPoint>(
            new DataPoint[] {
              new DataPoint(d1, 2),
              new DataPoint(d2, 3),
              new DataPoint(d3, 3),
              new DataPoint(d4, 4),
              new DataPoint(d5, 5),
              new DataPoint(d6, 5),
              new DataPoint(d7, 7),
              new DataPoint(d8, 4),
              new DataPoint(d9, 6),
            });
    series.setColor(getResources().getColor(android.R.color.holo_red_dark));
    graph.addSeries(series);
    graph.addSeries(series2);

    // set date label formatter
    graph
        .getGridLabelRenderer()
        .setLabelFormatter(new DateAsXAxisLabelFormatter(NativeGraphActivity.this));
    graph.getGridLabelRenderer().setNumHorizontalLabels(8); // only 4 because of the space

    // set manual x bounds to have nice steps
    graph.getViewport().setMinX(d1.getTime());
    graph.getViewport().setMaxX(d9.getTime());
    graph.getViewport().setXAxisBoundsManual(true);

    lecho.lib.hellocharts.view.LineChartView chartView = (LineChartView) findViewById(R.id.chart);
    List<PointValue> values = new ArrayList<PointValue>();
    values.add(new PointValue(0, 2));
    values.add(new PointValue(1, 4));
    values.add(new PointValue(2, 3));
    values.add(new PointValue(3, 4));

    // In most cased you can call data model methods in builder-pattern-like manner.
    Line line =
        new Line(values)
            .setColor(getResources().getColor(android.R.color.holo_red_dark))
            .setCubic(false);

    List<Line> lines = new ArrayList<Line>();
    lines.add(line);

    LineChartData data = new LineChartData();
    data.setLines(lines);
    Axis axis = new Axis();
    axis.setHasTiltedLabels(true);

    data.setAxisXBottom(new Axis().setAutoGenerated(true));
    data.setAxisYLeft(new Axis().setAutoGenerated(true));
    data.setBaseValue(20);

    chartView.setLineChartData(data);
  }