コード例 #1
0
 public Axis xAxis() {
   Axis xAxis = new Axis();
   xAxis.setAutoGenerated(false);
   List<AxisValue> xAxisValues = new ArrayList<AxisValue>();
   GregorianCalendar now = new GregorianCalendar();
   GregorianCalendar today =
       new GregorianCalendar(
           now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH));
   final java.text.DateFormat timeFormat = hourFormat();
   timeFormat.setTimeZone(TimeZone.getDefault());
   double start_hour_block = today.getTime().getTime();
   double timeNow = new Date().getTime();
   for (int l = 0; l <= 24; l++) {
     if ((start_hour_block + (60000 * 60 * (l))) < timeNow) {
       if ((start_hour_block + (60000 * 60 * (l + 1))) >= timeNow) {
         endHour = start_hour_block + (60000 * 60 * (l));
         l = 25;
       }
     }
   }
   for (int l = 0; l <= 24; l++) {
     double timestamp = (endHour - (60000 * 60 * l));
     xAxisValues.add(
         new AxisValue((long) (timestamp / FUZZER), (timeFormat.format(timestamp)).toCharArray()));
   }
   xAxis.setValues(xAxisValues);
   xAxis.setHasLines(true);
   xAxis.setTextSize(axisTextSize);
   return xAxis;
 }
コード例 #2
0
  public Axis yAxis() {
    Axis yAxis = new Axis();
    yAxis.setAutoGenerated(false);
    List<AxisValue> axisValues = new ArrayList<AxisValue>();

    //        for(int j = 1; j <= 12; j += 1) {
    //            if (doMgdl) {
    //                axisValues.add(new AxisValue(j * 50));
    //            } else {
    //                axisValues.add(new AxisValue(j*2));
    //            }
    //        }
    axisValues.add(new AxisValue(240));
    axisValues.add(new AxisValue((int) this.lowMark));
    axisValues.add(new AxisValue((int) this.highMark));
    yAxis.setValues(axisValues);
    yAxis.setHasLines(true);
    yAxis.setLineColor(Color.parseColor("#555555"));
    yAxis.setMaxLabelChars(5);
    yAxis.setInside(true);
    yAxis.setTextSize(axisTextSize);
    yAxis.setTextColor(Color.parseColor("#8D8D8D"));
    yAxis.setHasTiltedLabels(true);

    return yAxis;
  }
コード例 #3
0
  private void updateChart(int total) {
    int numSubcolumns = 60;
    int numColumns = 1000;
    List<float[]> flist = new ArrayList<>();
    //        if (!Constants.Queue_DrawRealtimewaterfall.isEmpty()) {
    //            flist = Constants.Queue_DrawRealtimewaterfall.poll();
    if (!Constants.Queue_DrawRealtimeSpectrum.isEmpty()) {
      flist = Constants.Queue_DrawRealtimeSpectrum.poll();
      int realsize = Constants.Queue_DrawRealtimeSpectrum.size();
      if (realsize >= 5) Constants.Queue_DrawRealtimeSpectrum.clear();
      List<Column> columns = new ArrayList<Column>();
      List<SubcolumnValue> values;
      if (flist.size() != total) {
        // 没收到整段就返回
        return;
      }
      float[] ff1 = selectData(flist);
      if (Xvalues.size() > 0) {
        int size = Xvalues.size();
        for (int i = 0; i < size; i++) {
          values = new ArrayList<SubcolumnValue>();
          values = Xvalues.get(i);
          for (int j = numSubcolumns - 1; j > 0; j--) {
            values.set(j, values.get(j - 1));
          }
          // int color=ChartUtils.pickColor();
          int index = (int) ((ff1[i] + 150) / 8);
          int color = 0;
          if (index >= 20) {
            color = colors[19];
          } else if (index < 0) {
            color = colors[0];
          } else {
            color = colors[(int) ((ff1[i] + 150) / 8)];
          }
          values.set(0, new SubcolumnValue(1, color));

          Column column = new Column(values);
          columns.add(column);
        }
      }
      data = new ColumnChartData(columns);
      data.setStacked(true);
      data.setFillRatio(1);
      Axis axisX = new Axis(Lvalues);
      Axis axisY = Axis.generateAxisFromRange(0, 60, 2);
      axisY.setLineColor(Color.GREEN);
      axisX.setHasLines(false);
      axisX.setHasSeparationLine(false);
      axisY.setHasSeparationLine(false);
      axisY.setHasLines(false);

      axisX.setName("Axis X");
      axisY.setName("Axis Y");
      data.setAxisXBottom(axisX);
      data.setAxisYLeft(axisY);
      chart.setColumnChartData(data);
    }
  }
コード例 #4
0
 public Axis previewXAxis() {
   List<AxisValue> previewXaxisValues = new ArrayList<AxisValue>();
   final java.text.DateFormat timeFormat = hourFormat();
   timeFormat.setTimeZone(TimeZone.getDefault());
   for (int l = 0; l <= 24; l += hoursPreviewStep) {
     double timestamp = (endHour - (60000 * 60 * l));
     previewXaxisValues.add(
         new AxisValue((long) (timestamp / FUZZER), (timeFormat.format(timestamp)).toCharArray()));
   }
   Axis previewXaxis = new Axis();
   previewXaxis.setValues(previewXaxisValues);
   previewXaxis.setHasLines(true);
   previewXaxis.setTextSize(previewAxisTextSize);
   return previewXaxis;
 }
コード例 #5
0
  /** Generates columns with stacked subcolumns. */
  private void generateStackedData(int start, int end) {
    int numSubcolumns = 60;
    int numColumns = 1000;
    List<Column> columns = new ArrayList<Column>();
    List<SubcolumnValue> values;
    Lvalues = new ArrayList<>();
    Xvalues = new ArrayList<List<SubcolumnValue>>();
    for (int i = 0; i < numColumns; ++i) {
      values = new ArrayList<SubcolumnValue>();
      if (i == 0) {
        Lvalues.add(new AxisValue(i).setLabel(String.valueOf(start)));
      } else if (i == numColumns - 30) {
        Lvalues.add(new AxisValue(i).setLabel(String.valueOf(end)));
      }
      for (int j = 1; j <= numSubcolumns; ++j) {
        values.add(new SubcolumnValue(1, Color.WHITE));
      }

      Column column = new Column(values);
      column.setHasLabelsOnlyForSelected(hasLabelForSelected);
      columns.add(column);

      Xvalues.add(values);
    }
    data = new ColumnChartData(columns);

    data.setStacked(true);
    data.setFillRatio(1);

    Axis axisX = new Axis(Lvalues);
    axisX.setHasSeparationLine(false);
    axisX.setHasLines(false);
    Axis axisY = Axis.generateAxisFromRange(0, 60, 1);
    axisY.setHasSeparationLine(false);
    axisY.setHasLines(false);
    axisY.setLineColor(Color.GREEN);

    axisX.setName("Axis X");
    axisY.setName("Axis Y");
    data.setAxisXBottom(axisX);
    data.setAxisYLeft(axisY);
    chart.setColumnChartData(data);
  }
コード例 #6
0
    // 产生数据 实时
    /////////////////////////////////////////////////////////////////////////////////////////
    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();
    }
コード例 #7
0
  ///////// AXIS RELATED//////////////
  public Axis yAxis() {
    Axis yAxis = new Axis();
    yAxis.setAutoGenerated(false);
    List<AxisValue> axisValues = new ArrayList<AxisValue>();

    for (int j = 1; j <= 12; j += 1) {
      if (doMgdl) {
        axisValues.add(new AxisValue(j * 50));
      } else {
        axisValues.add(new AxisValue(j * 2));
      }
    }
    yAxis.setValues(axisValues);
    yAxis.setHasLines(true);
    yAxis.setMaxLabelChars(5);
    yAxis.setInside(true);
    yAxis.setTextSize(axisTextSize);
    return yAxis;
  }
コード例 #8
0
  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();
  }
コード例 #9
0
 public Axis chartXAxis() {
   Axis xAxis = xAxis();
   xAxis.setTextSize(axisTextSize);
   return xAxis;
 }
コード例 #10
0
  @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);
  }