コード例 #1
0
ファイル: LineChart.java プロジェクト: yan96in/MPChartLib
  @Override
  protected void drawHighlights() {

    for (int i = 0; i < mIndicesToHightlight.length; i++) {

      LineDataSet set = mOriginalData.getDataSetByIndex(mIndicesToHightlight[i].getDataSetIndex());

      if (set == null) continue;

      mHighlightPaint.setColor(set.getHighLightColor());

      int xIndex = mIndicesToHightlight[i].getXIndex(); // get the
      // x-position

      if (xIndex > mDeltaX * mPhaseX) continue;

      float y = set.getYValForXIndex(xIndex) * mPhaseY; // get the
      // y-position

      float[] pts = new float[] {xIndex, mYChartMax, xIndex, mYChartMin, 0, y, mDeltaX, y};

      transformPointArray(pts);
      // draw the highlight lines
      mDrawCanvas.drawLines(pts, mHighlightPaint);
    }
  }
コード例 #2
0
  private void setData(int start, int count, float range) {

    ArrayList<String> xVals = new ArrayList<String>();
    for (int i = 0; i < count; i++) {
      xVals.add((start + i) + "日");
    }

    ArrayList<Entry> vals1 = new ArrayList<Entry>();

    for (int i = 0; i < count; i++) {
      vals1.add(new Entry(TurnControl.PunchPerDay[9 - i], i));
    }

    // create a dataset and give it a type
    LineDataSet set1 = new LineDataSet(vals1, "近期打卡情况");
    set1.setDrawCubic(true);
    set1.setCubicIntensity(0.2f);
    set1.setDrawFilled(true);
    set1.setDrawCircles(true);
    set1.setLineWidth(2f);
    set1.setCircleSize(5f);
    set1.setHighLightColor(Color.rgb(244, 117, 117));
    set1.setColor(Color.rgb(104, 241, 175));
    set1.setFillColor(ColorTemplate.getHoloBlue());

    // create a data object with the datasets
    LineData data = new LineData(xVals, set1);
    data.setValueTypeface(tf);
    data.setValueTextSize(9f);
    data.setDrawValues(false);

    // set data
    mChart.setData(data);
  }
コード例 #3
0
ファイル: LineChart.java プロジェクト: yan96in/MPChartLib
    @Override
    public float getFillLinePosition(
        LineDataSet dataSet, LineData data, float chartMaxY, float chartMinY) {

      float fillMin = 0f;

      if (dataSet.getYMax() > 0 && dataSet.getYMin() < 0) {
        fillMin = 0f;
      } else {

        if (!mStartAtZero) {

          float max, min;

          if (data.getYMax() > 0) max = 0f;
          else max = chartMaxY;
          if (data.getYMin() < 0) min = 0f;
          else min = chartMinY;

          fillMin = dataSet.getYMin() >= 0 ? min : max;
        } else {
          fillMin = 0f;
        }
      }

      return fillMin;
    }
コード例 #4
0
  /** Add the data of a specific signal type of a specific point to chart. */
  public void refreshChartOfSignal(MapPoint p, String signalTypeId) {
    LineChart chart = getChart(signalTypeId);
    ArrayList<LineDataSet> currentChartDataSets = new ArrayList<LineDataSet>();

    for (SignalDataSet ds : p.getDataSetsOfSignal(signalTypeId)) {
      // Log.i("NewPointActivity", "addToGraph ("+p+"): "+signalTypeId+",
      // "+ds.getSignalSourceId()+", "+ds.getDate()+", "+ds.size());

      LineDataSet chartDataSet = createChartDataSet(ds.getSignalSourceId(), ds.getDate());

      for (SignalSample s : ds.getSamples()) {
        if (s == null) {
          // @todo Each dataset must have its own null value.
          // Here the null value is fixed -150f.
          chartDataSet.addEntry(new Entry(-150f, chartDataSet.getEntryCount()));
        } else {
          // Add the sample to chart line.
          DoubleSignalSample doubleSignalSample = (DoubleSignalSample) s;
          chartDataSet.addEntry(
              new Entry(doubleSignalSample.getValue().floatValue(), chartDataSet.getEntryCount()));
        }
      }

      // Add the line to chart.
      currentChartDataSets.add(chartDataSet);

      // Updates table.
      updateDataTable(ds);
    }

    refreshChart(chart, currentChartDataSets);
  }
コード例 #5
0
  private void setData(int count, float range) {

    ArrayList<String> xVals = new ArrayList<String>();
    for (int i = 0; i < count; i++) {
      xVals.add((i % 30) + "/" + (i % 12) + "/14");
    }

    ArrayList<Entry> yVals = new ArrayList<Entry>();

    for (int i = 0; i < count; i++) {
      float mult = (range + 1);
      float val = (float) (Math.random() * mult) + 3; // + (float)
      // ((mult *
      // 0.1) / 10);
      yVals.add(new Entry(val, i));
    }

    // create a dataset and give it a type
    LineDataSet set1 = new LineDataSet(yVals, "DataSet 1");

    set1.setLineWidth(1.5f);
    set1.setCircleSize(4f);

    // create a data object with the datasets
    LineData data = new LineData(xVals, set1);

    // set data
    mChart.setData(data);
  }
コード例 #6
0
  /**
   * Creates a LineDataSet object.
   *
   * @param signalSourceId
   * @param date
   * @return
   */
  public LineDataSet createChartDataSet(String signalSourceId, Date date) {
    LineDataSet lineDataSet = new LineDataSet(new ArrayList<Entry>(), signalSourceId);
    int color = getColor(signalSourceId);
    lineDataSet.setColors(new int[] {color});
    lineDataSet.setDrawCircles(false);

    return lineDataSet;
  }
コード例 #7
0
  private void loadData(boolean drawLast) {
    ChartCollection collection =
        fromDevice ? fileManager.getCollection() : fileManager.getPcaCollection();
    if (collection != null) {
      int size = collection.size();
      if (size > 0) {
        List<Entry> entries = new ArrayList<>();
        List<String> xVals = new ArrayList<>();

        ChartData data = collection.getCharData(size - 1);
        Map<Double, Double> values = data.getData();
        List<Double> keyList = new ArrayList<>();
        keyList.addAll(values.keySet());
        Collections.sort(keyList);

        for (Double x : keyList) {
          Number numX = x;
          int intX = numX.intValue();
          xVals.add(String.valueOf(x));

          double value = values.get(x);

          Number num = value;
          float val = num.floatValue();
          Entry entry = new Entry(val, intX);
          entries.add(entry);
        }

        LineDataSet dataSet = new LineDataSet(entries, "Dados");
        dataSet.setDrawCircleHole(false);
        dataSet.setDrawCircles(false);
        LineData chartData = new LineData(xVals, dataSet);
        chart.setData(chartData);

        totalGraphs = size;
        if (drawLast) {
          currentGraph = totalGraphs;
        } else {
          if (currentGraph < 1 || currentGraph > size) {
            currentGraph = totalGraphs;
          }
        }

        mainHandler.post(
            new Runnable() {
              @Override
              public void run() {
                chart.notifyDataSetChanged();
                chart.invalidate();

                txtTotal.setText(String.valueOf(totalGraphs));
                txtCurrent.setText(String.valueOf(currentGraph));
              }
            });
      }
    }
  }
コード例 #8
0
ファイル: LineChart.java プロジェクト: yan96in/MPChartLib
  @Override
  protected void drawValues() {

    // if values are drawn
    if (mDrawYValues && mCurrentData.getYValCount() < mMaxVisibleCount * mScaleX) {

      ArrayList<LineDataSet> dataSets = mCurrentData.getDataSets();

      for (int i = 0; i < mCurrentData.getDataSetCount(); i++) {

        LineDataSet dataSet = dataSets.get(i);

        // make sure the values do not interfear with the circles
        int valOffset = (int) (dataSet.getCircleSize() * 1.75f);

        if (!dataSet.isDrawCirclesEnabled()) valOffset = valOffset / 2;

        ArrayList<Entry> entries = dataSet.getYVals();

        float[] positions = generateTransformedValuesLineScatter(entries);

        for (int j = 0; j < positions.length * mPhaseX; j += 2) {

          if (isOffContentRight(positions[j])) break;

          if (isOffContentLeft(positions[j])
              || isOffContentTop(positions[j + 1])
              || isOffContentBottom(positions[j + 1])) continue;

          float val = entries.get(j / 2).getVal();

          if (mDrawUnitInChart) {

            mDrawCanvas.drawText(
                mValueFormatter.getFormattedValue(val) + mUnit,
                positions[j],
                positions[j + 1] - valOffset,
                mValuePaint);
          } else {

            mDrawCanvas.drawText(
                mValueFormatter.getFormattedValue(val),
                positions[j],
                positions[j + 1] - valOffset,
                mValuePaint);
          }
        }
      }
    }
  }
コード例 #9
0
  /**
   * Refreshs a chart.
   *
   * @param chart
   * @param chartDataSets
   */
  public void refreshChart(LineChart chart, ArrayList<LineDataSet> chartDataSets) {
    // Populates X List.
    // Identifies the biggets dataset.
    int maxSize = 0;
    for (LineDataSet dataSet : chartDataSets)
      if (dataSet.getEntryCount() > maxSize) maxSize = dataSet.getEntryCount();

    ArrayList<String> xVals = new ArrayList<String>();
    while (xVals.size() < maxSize) xVals.add((xVals.size() + 1) + "");

    LineData chartData = new LineData(xVals, chartDataSets);
    chart.setData(chartData);
    chart.notifyDataSetChanged();
    chart.invalidate();
  }
コード例 #10
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    DateFormat df =
        new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); // défini un nouveau format de date en string
    ViewGroup rootView =
        (ViewGroup) inflater.inflate(R.layout.fragment_statistics_linechart, container, false);

    LineChart chart = (LineChart) rootView.findViewById(R.id.firstChart);
    chart.setLogEnabled(true);
    chart.setNoDataTextDescription(getString(R.string.no_data));

    ArrayList<DrinkIncome> incomesByDrink = getIncomes();

    ArrayList<Entry> Income1 =
        new ArrayList<Entry>(); // creation d'un arrayList d'entrées pour le tableau
    ArrayList<Entry[]> drink2 = new ArrayList<Entry[]>();
    ArrayList<Entry> drink3 = new ArrayList<Entry>();
    ArrayList<Entry> drink4 = new ArrayList<Entry>();
    ArrayList<Entry> drink5 = new ArrayList<Entry>();
    ArrayList<String> xVals =
        new ArrayList<String>(); // creation d'une arrayList pour les valeurs des abscisses

    Iterator<DrinkIncome> it = incomesByDrink.iterator();
    for (int i = 0; it.hasNext() && i < 5; i++) {
      DrinkIncome s = it.next();
      Entry element = new Entry(s.getIncome(), i);
      Income1.add(element);
      // xVals.add(df.format(s.getDateOrder()));
      xVals.add("J-" + i);
    }

    LineDataSet setBestDrinks = new LineDataSet(Income1, getString(R.string.daily_incomes));
    setBestDrinks.setDrawFilled(true);
    setBestDrinks.setColors(
        new int[] {R.color.blue1, R.color.blue2, R.color.blue3, R.color.blue1},
        rootView.getContext());

    ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
    dataSets.add(setBestDrinks);

    LineData data = new LineData(xVals, dataSets);
    chart.setData(data);

    return rootView;
  }
コード例 #11
0
ファイル: Kommfort.java プロジェクト: BestShift/android-app
  private void addEntry() {
    LineData data = mLineChart.getData();
    if (data != null) {
      LineDataSet set = data.getDataSetByIndex(0);
      if (set == null) {
        set = createSet();
        data.addDataSet(set);
      }
      // add a new random value
      float a = r.nextFloat() * (2.00f + 2.00f) - 2.0f;
      System.out.println(a);
      data.addXValue("");
      data.addEntry(new Entry(a, set.getEntryCount()), 0);

      mLineChart.notifyDataSetChanged();

      mLineChart.setVisibleXRange(6, 0);

      mLineChart.moveViewToX(data.getXValCount() - 7);
    }
  }
コード例 #12
0
  @Override
  public void onResponse(Response<List<Purchase>> response) {
    if (!response.isSuccess()) {
      return;
    }

    List<Purchase> purchases = response.body();

    if (purchases.size() < 2) {
      setAlpha(.2f);
      purchases = PLACEHOLDER_DATA;
    } else {
      setAlpha(1);
    }

    ArrayList<String> xVals = new ArrayList<>();
    ArrayList<Entry> yVals = new ArrayList<>();
    for (int i = 0; i < purchases.size(); i++) {
      xVals.add(String.valueOf(i));
      yVals.add(new Entry(purchases.get(purchases.size() - i - 1).amount, i));
    }

    LineDataSet dataSet = new LineDataSet(yVals, "Purchases");
    dataSet.setDrawValues(false);
    dataSet.setDrawCircles(false);
    dataSet.setColor(Color.WHITE);
    dataSet.setDrawFilled(true);
    dataSet.setFillColor(Color.WHITE);
    setData(new LineData(xVals, Collections.singletonList(dataSet)));

    invalidate();
  }
コード例 #13
0
ファイル: LineChart.java プロジェクト: yan96in/MPChartLib
  /** draws the circle value indicators */
  @Override
  protected void drawAdditional() {

    mRenderPaint.setStyle(Paint.Style.FILL);

    ArrayList<LineDataSet> dataSets = mCurrentData.getDataSets();

    for (int i = 0; i < mCurrentData.getDataSetCount(); i++) {

      LineDataSet dataSet = dataSets.get(i);

      // if drawing circles is enabled for this dataset
      if (dataSet.isDrawCirclesEnabled()) {

        ArrayList<Entry> entries = dataSet.getYVals();

        float[] positions = generateTransformedValuesLineScatter(entries);

        for (int j = 0; j < positions.length * mPhaseX; j += 2) {

          // Set the color for the currently drawn value. If the index
          // is
          // out of bounds, reuse colors.
          mRenderPaint.setColor(dataSet.getCircleColor(j / 2));

          if (isOffContentRight(positions[j])) break;

          // make sure the circles don't do shitty things outside
          // bounds
          if (isOffContentLeft(positions[j])
              || isOffContentTop(positions[j + 1])
              || isOffContentBottom(positions[j + 1])) continue;

          mDrawCanvas.drawCircle(
              positions[j], positions[j + 1], dataSet.getCircleSize(), mRenderPaint);
          mDrawCanvas.drawCircle(
              positions[j], positions[j + 1], dataSet.getCircleSize() / 2f, mCirclePaintInner);
        }
      } // else do nothing
    }
  }
コード例 #14
0
ファイル: LineChart.java プロジェクト: yan96in/MPChartLib
  /** draws the given y values to the screen */
  @Override
  protected void drawData() {

    ArrayList<LineDataSet> dataSets = mCurrentData.getDataSets();

    for (int i = 0; i < mCurrentData.getDataSetCount(); i++) {

      LineDataSet dataSet = dataSets.get(i);
      ArrayList<Entry> entries = dataSet.getYVals();

      if (entries.size() < 1) continue;

      mRenderPaint.setStrokeWidth(dataSet.getLineWidth());
      mRenderPaint.setPathEffect(dataSet.getDashPathEffect());

      // if drawing cubic lines is enabled
      if (dataSet.isDrawCubicEnabled()) {

        // get the color that is specified for this position from the
        // DataSet
        mRenderPaint.setColor(dataSet.getColor());

        float intensity = dataSet.getCubicIntensity();

        // the path for the cubic-spline
        Path spline = new Path();

        ArrayList<CPoint> points = new ArrayList<CPoint>();
        for (Entry e : entries) points.add(new CPoint(e.getXIndex(), e.getVal()));

        if (points.size() > 1) {
          for (int j = 0; j < points.size() * mPhaseX; j++) {

            CPoint point = points.get(j);

            if (j == 0) {
              CPoint next = points.get(j + 1);
              point.dx = ((next.x - point.x) * intensity);
              point.dy = ((next.y - point.y) * intensity);
            } else if (j == points.size() - 1) {
              CPoint prev = points.get(j - 1);
              point.dx = ((point.x - prev.x) * intensity);
              point.dy = ((point.y - prev.y) * intensity);
            } else {
              CPoint next = points.get(j + 1);
              CPoint prev = points.get(j - 1);
              point.dx = ((next.x - prev.x) * intensity);
              point.dy = ((next.y - prev.y) * intensity);
            }

            // create the cubic-spline path
            if (j == 0) {
              spline.moveTo(point.x, point.y * mPhaseY);
            } else {
              CPoint prev = points.get(j - 1);
              spline.cubicTo(
                  prev.x + prev.dx,
                  (prev.y + prev.dy) * mPhaseY,
                  point.x - point.dx,
                  (point.y - point.dy) * mPhaseY,
                  point.x,
                  point.y * mPhaseY);
            }
          }
        }

        // if filled is enabled, close the path
        if (dataSet.isDrawFilledEnabled()) {

          float fillMin =
              mFillFormatter.getFillLinePosition(dataSet, mOriginalData, mYChartMax, mYChartMin);

          spline.lineTo((entries.size() - 1) * mPhaseX, fillMin);
          spline.lineTo(0, fillMin);
          spline.close();

          mRenderPaint.setStyle(Paint.Style.FILL);
        } else {
          mRenderPaint.setStyle(Paint.Style.STROKE);
        }

        transformPath(spline);

        mDrawCanvas.drawPath(spline, mRenderPaint);

        // draw normal (straight) lines
      } else {

        mRenderPaint.setStyle(Paint.Style.STROKE);

        // more than 1 color
        if (dataSet.getColors() == null || dataSet.getColors().size() > 1) {

          float[] valuePoints = generateTransformedValuesLineScatter(entries);

          for (int j = 0; j < (valuePoints.length - 2) * mPhaseX; j += 2) {

            if (isOffContentRight(valuePoints[j])) break;

            // make sure the lines don't do shitty things outside
            // bounds
            if (j != 0
                && isOffContentLeft(valuePoints[j - 1])
                && isOffContentTop(valuePoints[j + 1])
                && isOffContentBottom(valuePoints[j + 1])) continue;

            // get the color that is set for this line-segment
            mRenderPaint.setColor(dataSet.getColor(j / 2));

            mDrawCanvas.drawLine(
                valuePoints[j],
                valuePoints[j + 1],
                valuePoints[j + 2],
                valuePoints[j + 3],
                mRenderPaint);
          }

        } else { // only one color per dataset

          mRenderPaint.setColor(dataSet.getColor());

          Path line = generateLinePath(entries);
          transformPath(line);

          mDrawCanvas.drawPath(line, mRenderPaint);
        }

        mRenderPaint.setPathEffect(null);

        // if drawing filled is enabled
        if (dataSet.isDrawFilledEnabled() && entries.size() > 0) {
          // mDrawCanvas.drawVertices(VertexMode.TRIANGLE_STRIP,
          // valuePoints.length, valuePoints, 0,
          // null, 0, null, 0, null, 0, 0, paint);

          mRenderPaint.setStyle(Paint.Style.FILL);

          mRenderPaint.setColor(dataSet.getFillColor());
          // filled is drawn with less alpha
          mRenderPaint.setAlpha(dataSet.getFillAlpha());

          // mRenderPaint.setShader(dataSet.getShader());

          Path filled =
              generateFilledPath(
                  entries,
                  mFillFormatter.getFillLinePosition(
                      dataSet, mOriginalData, mYChartMax, mYChartMin));

          transformPath(filled);

          mDrawCanvas.drawPath(filled, mRenderPaint);

          // restore alpha
          mRenderPaint.setAlpha(255);
          // mRenderPaint.setShader(null);
        }
      }

      mRenderPaint.setPathEffect(null);
    }
  }
コード例 #15
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_status, container, false);

    // TODO Need lot of design changes in chart
    // TODO Have to update LineChart with CombineChart to display LineChart with BarChart
    mChart = (LineChart) view.findViewById(R.id.chartInsight);
    mChart.setDescription("");
    mChart.setBackgroundColor(Color.WHITE);
    mChart.setDrawGridBackground(false);

    LineData d = new LineData();
    ArrayList<Entry> entries = new ArrayList<>();

    for (int index = 0; index < 12; index++) entries.add(new Entry(getRandom(25, 10), index));

    LineDataSet set = new LineDataSet(entries, "DataSet1");
    set.setColor(Color.rgb(240, 238, 70));
    set.setLineWidth(2.5f);
    set.setCircleColor(Color.rgb(240, 238, 70));
    set.setCircleSize(5f);
    set.setFillColor(Color.rgb(240, 238, 70));
    set.setDrawCubic(true);
    set.setDrawValues(true);
    set.setValueTextSize(10f);
    set.setValueTextColor(Color.rgb(240, 238, 70));

    for (int index = 0; index < 12; index++) entries.add(new Entry(getRandom(25, 10), index));

    LineDataSet set2 = new LineDataSet(entries, "DataSet2");
    set.setColor(Color.rgb(240, 238, 70));
    set.setLineWidth(2.5f);
    set.setCircleColor(Color.rgb(240, 238, 70));
    set.setCircleSize(5f);
    set.setFillColor(Color.rgb(240, 238, 70));
    set.setDrawCubic(true);
    set.setDrawValues(true);
    set.setValueTextSize(10f);
    set.setValueTextColor(Color.rgb(240, 238, 70));

    set.setAxisDependency(YAxis.AxisDependency.LEFT);

    d.addDataSet(set);
    d.addDataSet(set2);

    mChart.setData(d);
    mChart.setDescription("Fuel Insight");
    mChart.animateXY(2000, 2000);
    mChart.invalidate();

    //        String[] projection = { FuelContract.COLUMN_AMOUNT, FuelContract.COLUMN_ID };
    //        Cursor fuelData =
    // inflater.getContext().getContentResolver().query(FuelProvider.FUEL_CONTENT_URI, projection,
    // null, null, null);
    //        while (fuelData.getCount()!=0) {
    //            fuelData.moveToNext();
    //            Log.i("FuelData", "ID: " + fuelData.getString(1) + "  Amount: " +
    // fuelData.getString(0));
    //        }
    return view;
  }
コード例 #16
0
ファイル: KLineActivity.java プロジェクト: XYupup/StockChart
 @NonNull
 private LineDataSet setMaLine(int ma, ArrayList<String> xVals, ArrayList<Entry> lineEntries) {
   LineDataSet lineDataSetMa = new LineDataSet(lineEntries, "ma" + ma);
   if (ma == 5) {
     lineDataSetMa.setHighlightEnabled(true);
     lineDataSetMa.setDrawHorizontalHighlightIndicator(false);
     lineDataSetMa.setHighLightColor(Color.WHITE);
   } else {
       /*此处必须得写*/
     lineDataSetMa.setHighlightEnabled(false);
   }
   lineDataSetMa.setDrawValues(false);
   if (ma == 5) {
     lineDataSetMa.setColor(Color.GREEN);
   } else if (ma == 10) {
     lineDataSetMa.setColor(Color.GRAY);
   } else {
     lineDataSetMa.setColor(Color.YELLOW);
   }
   lineDataSetMa.setLineWidth(1f);
   lineDataSetMa.setDrawCircles(false);
   lineDataSetMa.setAxisDependency(YAxis.AxisDependency.LEFT);
   return lineDataSetMa;
 }
コード例 #17
0
  private void setData(int count, float range) {

    // only using first meter for now.
    // TODO: graph multiple meters?
    Meter meter = mMeters.get(0);
    List<MeterReading> readings = meter.getReadings();

    ArrayList<Entry> averageEntries = new ArrayList<Entry>();

    // build up X-axis labels; e.g., dates.
    // build up Y-axis with values;
    // skip first date as we can't determine consumption.
    ArrayList<String> xVals = new ArrayList<String>();
    ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
    float runningTotal = 0;
    float dailyAverage;
    for (int lv = 1; lv < count; lv++) {
      MeterReading prevReading = readings.get(lv - 1);
      MeterReading currReading = readings.get(lv);

      xVals.add(removeYearFromDate(currReading.getTimeStamp()));
      float val = (currReading.getConsumption() - prevReading.getConsumption()) * 10;
      yVals1.add(new BarEntry(val, lv - 1));

      // calc & store daily average.
      runningTotal += val;
      dailyAverage = runningTotal / lv;
      averageEntries.add(new Entry(dailyAverage, lv - 1));
    }

    // TODO: allow name to be updated.
    BarDataSet set1 = new BarDataSet(yVals1, "mine");
    set1.setBarSpacePercent(35f);

    ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
    dataSets.add(set1);

    // bar chart data
    BarData barData = new BarData(xVals, dataSets);
    barData.setValueFormatter(new MyValueFormatter());
    barData.setValueTextSize(10f);

    // line chart data
    LineData lineData = new LineData();
    LineDataSet set = new LineDataSet(averageEntries, "average");
    int lineColor = Color.rgb(251, 169, 165);
    set.setColor(lineColor);
    set.setLineWidth(1.5f);
    set.setDrawCircles(false);
    set.setFillColor(lineColor);
    set.setDrawCubic(true);
    set.setDrawValues(false);
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    lineData.addDataSet(set);

    CombinedData combinedData = new CombinedData(getDates(meter.getReadings()));
    combinedData.setData(barData);
    combinedData.setData(lineData);

    mChart.setData(combinedData);
    mChart.invalidate();
  }
コード例 #18
0
ファイル: Kommfort.java プロジェクト: BestShift/android-app
  private LineDataSet createSet() {

    LineDataSet set = new LineDataSet(null, "Realtime Beschleunigungskraefte");
    set.setDrawCubic(true);
    set.setCubicIntensity(0.2f);
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    set.setColor(ColorTemplate.getHoloBlue());
    set.setCircleColor(Color.BLACK);
    set.setLineWidth(2f);
    set.setCircleSize(4f);
    set.setFillAlpha(65);
    set.setFillColor(ColorTemplate.getHoloBlue());
    set.setHighLightColor(Color.rgb(244, 117, 117));
    set.setValueTextColor(Color.BLACK);
    set.setValueTextSize(10f);
    return set;
  }
コード例 #19
0
  public void drawLineChart(
      View v,
      int averageCrowdValue,
      List<Integer> todaysCrowdValues,
      List<Integer> rodCrowdValues) {

    /* Create data entries1 and labels for todaysCrowd Values*/
    ArrayList<Entry> entries1 = new ArrayList<>();
    ArrayList<String> labels = new ArrayList<>();
    for (int hour = 0; hour < todaysCrowdValues.size(); hour++) {
      entries1.add(new Entry(todaysCrowdValues.get(hour), hour));
      labels.add("" + hour);
    }

    /* Create data entries2 and labels for rodCrowdValues Values*/
    ArrayList<Entry> entries2 = new ArrayList<>();
    for (int hour = 0; hour < rodCrowdValues.size(); hour++) {
      entries2.add(new Entry(rodCrowdValues.get(hour), hour + todaysCrowdValues.size()));
      labels.add("" + (hour + todaysCrowdValues.size()));
    }

    /* Create dataentires for averageCrowdValue */
    ArrayList<Entry> entries3 = new ArrayList<>();
    entries3.add(new Entry(averageCrowdValue, 0));
    entries3.add(new Entry(averageCrowdValue, 23));

    // Create dataset from data entries1
    LineDataSet dataset1 = new LineDataSet(entries1, "Today's Crowd");
    LineDataSet dataset2 = new LineDataSet(entries2, "Predicted Crowd");
    LineDataSet dataset3 = new LineDataSet(entries3, "Average Crowd");

    // Set the color for this dataset
    dataset1.setColor(Color.rgb(0, 37, 76)); // GT Navy
    dataset2.setColor(Color.rgb(238, 178, 17)); // Buzz Gold
    dataset3.setColor(Color.rgb(197, 147, 83)); // GT Gold

    // Aggregate all data sets
    ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
    dataSets.add(dataset1);
    dataSets.add(dataset2);
    dataSets.add(dataset3);

    /* Create the chart */
    LineChart chart = (LineChart) v.findViewById(R.id.chart);

    // Hide Labels and grid lines from x axis
    chart.getXAxis().setDrawGridLines(false);
    chart.getXAxis().setDrawLabels(false);

    // Hide labels and grid lines from y axis
    chart.getAxisLeft().setDrawGridLines(false);
    chart.getAxisLeft().setDrawLabels(false);
    chart.getAxisRight().setDrawGridLines(false);
    chart.getAxisRight().setDrawLabels(false);

    // Dont label each node on graph
    chart.setDrawMarkerViews(false);
    LineData data = new LineData(labels, dataSets);
    chart.setData(data);

    chart.setDescription("Today's Crowd");

    // animations
    chart.animateY(1000);
  }
コード例 #20
0
ファイル: GraphHelper.java プロジェクト: konecnyna/BankWidget
 public void formatDataSet(LineDataSet set, @ColorInt int color) {
   set.setColor(color);
   set.setLineWidth(2.5f);
   set.setCircleColor(color);
   set.setCircleSize(5f);
   set.setFillColor(color);
   set.setDrawCubic(true);
   set.setValueTextSize(10f);
   set.setDrawValues(false);
   set.setDrawCircles(false);
   set.setValueTextColor(color);
   set.setDrawFilled(true);
 }
コード例 #21
0
  private LineDataSet createSet() {
    LineDataSet set = new LineDataSet(null, "Dynamic Data");
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    set.setColor(ColorTemplate.getHoloBlue());
    set.setCircleColor(Color.WHITE);
    set.setLineWidth(2f);
    set.setCircleSize(4f);
    set.setFillAlpha(65);
    set.setFillColor(ColorTemplate.getHoloBlue());
    set.setHighLightColor(Color.rgb(244, 117, 117));
    set.setValueTextColor(Color.WHITE);
    set.setValueTextSize(9f);
    set.setDrawValues(false);

    return set;
  }
コード例 #22
0
  private void drawChart() {
    BPRecord[] recs = mRecords;
    LineChart chart = (LineChart) findViewById(R.id.chart);
    ArrayList<Entry> valsHigh = new ArrayList<Entry>();
    ArrayList<Entry> valsLow = new ArrayList<Entry>();
    // ArrayList<Entry> heartRate = new ArrayList<Entry>();
    // ArrayList<Entry> o2Index = new ArrayList<Entry>();
    // ArrayList<Entry> avgArtP = new ArrayList<Entry>();
    ArrayList<String> xVals = new ArrayList<String>();
    Date firstTime = null;
    SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    SimpleDateFormat f2 = new SimpleDateFormat("MM/dd HH:mm");
    for (int i = 0; i < recs.length; ++i) {
      BPRecord rec = recs[i];
      int x = 0; // minutes from first data
      Date time = new Date();
      try {
        time = f.parse(rec.dateTime);
      } catch (ParseException ex) {
        Log.d("GetBPDate", "Exception:" + ex.toString());
        continue;
      }
      if (firstTime == null) {
        firstTime = time;
      } else {
        x = (int) ((time.getTime() - firstTime.getTime()) / 60000);
      }
      x = i;
      xVals.add(f2.format(time));
      valsHigh.add(new Entry(rec.systolic, x));
      valsLow.add(new Entry(rec.diastolic, x));
      // heartRate.add(new Entry(rec.heartRate,x));
      // avgArtP.add(new Entry(rec.avg_art_pressure,x));
      // o2Index.add(new Entry(rec.o2Index/100,x));
    }
    String hp = getResources().getString(R.string.hightPressure);
    String lp = getResources().getString(R.string.lowPressure);
    /*
    String hr = getResources().getString(R.string.heartBeatLabel);
    String avgAP = getResources().getString(R.string.average_artery_pressure);
    String o2 = getResources().getString(R.string.O2Index);
    */
    LineDataSet setHigh = new LineDataSet(valsHigh, hp);
    setHigh.setAxisDependency(YAxis.AxisDependency.LEFT);
    setHigh.setDrawCircles(false);
    setHigh.setColor(Color.RED);
    setHigh.setValueFormatter(new IntFormatter());
    setHigh.setValueTextSize(10);
    LineDataSet setLow = new LineDataSet(valsLow, lp);
    setLow.setAxisDependency(YAxis.AxisDependency.LEFT);
    setLow.setColor(Color.BLUE);
    setLow.setDrawCircles(false);
    setLow.setValueFormatter(new IntFormatter());
    setLow.setValueTextSize(10);
    /*
    LineDataSet setHr = new LineDataSet(heartRate, hr);
    setHr.setAxisDependency(YAxis.AxisDependency.LEFT);
    setHr.setColor(Color.GREEN);
    setHr.setDrawCircles(false);
    setHr.setValueFormatter(new IntFormatter());
    setHr.setValueTextSize(10);
    LineDataSet setAAP = new LineDataSet(avgArtP, avgAP);
    setAAP.setAxisDependency(YAxis.AxisDependency.LEFT);
    setAAP.setColor(Color.DKGRAY);
    setAAP.setDrawCircles(false);
    setAAP.setValueFormatter(new IntFormatter());
    setAAP.setValueTextSize(10);
    LineDataSet setO2 = new LineDataSet(o2Index, o2);
    setO2.setAxisDependency(YAxis.AxisDependency.LEFT);
    setO2.setColor(Color.CYAN);
    setO2.setDrawCircles(false);
    setO2.setValueFormatter(new IntFormatter());
    setO2.setValueTextSize(10);
    */
    ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
    dataSets.add(setHigh);
    dataSets.add(setLow);
    /*
    dataSets.add(setHr);
    dataSets.add(setAAP);
    dataSets.add(setO2);
    */

    /*
    xVals.add("12-15"); xVals.add("12-17"); xVals.add("12-18"); xVals.add("12-20");
    xVals.add("12-21"); xVals.add("12-22"); xVals.add("12-23"); xVals.add("12-24");
    */

    LineData data = new LineData(xVals, dataSets);
    // chart.setGridBackgroundColor(Color.BLACK);
    // chart.getLegend().setEnabled(false);
    chart.setData(data);
    chart.setDescription(getResources().getString(R.string.blood_pressure));
    chart.invalidate(); // refresh
  }