private void setupWeekStepsChart() {
    mWeekStepsChart.setBackgroundColor(BACKGROUND_COLOR);
    mWeekStepsChart.setDescriptionColor(DESCRIPTION_COLOR);
    mWeekStepsChart.setDescription("");

    configureBarLineChartDefaults(mWeekStepsChart);

    XAxis x = mWeekStepsChart.getXAxis();
    x.setDrawLabels(true);
    x.setDrawGridLines(false);
    x.setEnabled(true);
    x.setTextColor(CHART_TEXT_COLOR);
    x.setDrawLimitLinesBehindData(true);

    YAxis y = mWeekStepsChart.getAxisLeft();
    y.setDrawGridLines(false);
    y.setDrawTopYLabelEntry(false);
    y.setTextColor(CHART_TEXT_COLOR);

    y.setEnabled(true);

    YAxis yAxisRight = mWeekStepsChart.getAxisRight();
    yAxisRight.setDrawGridLines(false);
    yAxisRight.setEnabled(false);
    yAxisRight.setDrawLabels(false);
    yAxisRight.setDrawTopYLabelEntry(false);
    yAxisRight.setTextColor(CHART_TEXT_COLOR);
  }
Пример #2
0
  private void initChart() {
    mChart.setVisibility(View.VISIBLE);
    mChart.setDrawBarShadow(false);
    mChart.setDrawValueAboveBar(true);

    mChart.setDescription("");

    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    mChart.setMaxVisibleValueCount(60);

    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);

    // draw shadows for each bar that show the maximum value
    // mChart.setDrawBarShadow(true);

    // mChart.setDrawXLabels(false);

    mChart.setDrawGridBackground(false);
    // mChart.setDrawYLabels(false);

    mTf = Typeface.createFromAsset(getActivity().getAssets(), "OpenSans-Regular.ttf");

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setTypeface(mTf);
    xAxis.setDrawGridLines(false);
    xAxis.setSpaceBetweenLabels(2);

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(mTf);
    leftAxis.setLabelCount(8, false);
    leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
    leftAxis.setSpaceTop(15f);
    leftAxis.setValueFormatter(new YUnitFormatter("L"));

    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setTypeface(mTf);
    rightAxis.setEnabled(false);

    Legend l = mChart.getLegend();
    l.setPosition(Legend.LegendPosition.BELOW_CHART_CENTER);
    l.setForm(Legend.LegendForm.SQUARE);
    l.setFormSize(9f);
    l.setTextSize(11f);
    l.setXEntrySpace(4f);

    setData(12, 50);

    // dont forget to refresh the drawing
    getActivity()
        .runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                mChart.invalidate();
              }
            });
  }
  private void initChart(ClimbingArea climbingArea) {
    // Init first chart
    mChart = (BarChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);

    mChart.getLegend().setEnabled(false);
    mChart.setDrawBarShadow(false);
    mChart.setDrawValueAboveBar(true);
    mChart.getDescription().setEnabled(false);

    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    mChart.setMaxVisibleValueCount(60);

    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);
    mChart.setDoubleTapToZoomEnabled(false);
    mChart.setDragEnabled(false);
    mChart.setScaleEnabled(false);
    mChart.setDrawGridBackground(false);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setDrawGridLines(false);
    xAxis.setLabelCount(2);

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setEnabled(false);

    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setEnabled(false);
  }
Пример #4
0
 public BarChartBuilder(
     BarChart barChart,
     String description,
     String units,
     int maxVisibleValue,
     boolean drawXLabels,
     boolean drawLegend) {
   this.description = description;
   this.units = units;
   this.maxVisibleValue = maxVisibleValue;
   this.drawXLabels = drawXLabels;
   this.drawLegend = drawLegend;
   barChart.setDrawValueAboveBar(true);
   barChart.setMaxVisibleValueCount(maxVisibleValue);
   barChart.setDrawGridBackground(false);
   barChart.setDrawBarShadow(false);
   barChart.setDescription(description);
   barChart.setClickable(false);
   barChart.setPinchZoom(false);
   XAxis xL = barChart.getXAxis();
   xL.setPosition(XAxis.XAxisPosition.BOTTOM);
   xL.setDrawGridLines(false);
   YAxis yL = barChart.getAxisLeft();
   yL.setLabelCount(10, true);
   yL.setTextSize(10.0f);
   yL.setDrawGridLines(false);
   yL.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
   barChart.getAxisRight().setEnabled(false);
   this.barChart = barChart;
 }
  @Override
  public View getView(int position, View convertView, Context c) {

    ViewHolder holder = null;

    if (convertView == null) {

      holder = new ViewHolder();

      convertView = LayoutInflater.from(c).inflate(R.layout.listview_item_horizontalbarchart, null);
      holder.chart = (HorizontalBarChart) convertView.findViewById(R.id.horizontal_bar_chart);

      convertView.setTag(holder);

    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    BarData barData = (BarData) mChartData;
    // mRealmHandler.getSpecificDateAmount(month, year, 2);
    // apply styling
    holder.chart.setDescription("");
    holder.chart.setDrawGridBackground(false);
    holder.chart.setDrawBarShadow(false);
    //        holder.chart.setBackgroundColor(backgroundColor);

    holder.chart.getAxisLeft().setEnabled(false);
    holder.chart.getAxisRight().setStartAtZero(false);
    holder.chart.getAxisRight().setAxisMaxValue(total);
    holder.chart.getAxisRight().setAxisMinValue(-total);
    holder.chart.getAxisRight().setTextSize(9f);
    holder.chart.getAxisRight().setTextColor(Color.WHITE);

    XAxis xAxis = holder.chart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTH_SIDED);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setTextSize(9f);
    xAxis.setTextColor(Color.WHITE);

    Legend l = holder.chart.getLegend();
    l.setPosition(Legend.LegendPosition.BELOW_CHART_RIGHT);
    l.setFormSize(8f);
    l.setFormToTextSpace(4f);
    l.setXEntrySpace(6f);
    l.setTextColor(Color.WHITE);

    // mChartData.setValueTypeface(mTf);

    // set data
    holder.chart.setData(barData);

    holder.chart.animateY(700);
    holder.chart.notifyDataSetChanged();
    holder.chart.invalidate();

    return convertView;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View barChartLayout = inflater.inflate(R.layout.fragment_bar_chart, container, false);

    ButterKnife.bind(this, barChartLayout);

    mSwipeRefreshLayout.setOnRefreshListener(this);

    mChart.setOnChartValueSelectedListener(this);

    mChart.setDrawBarShadow(false);
    mChart.setDrawValueAboveBar(true);

    mChart.setDescription("");

    // TODO: do we care about this?
    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    mChart.setMaxVisibleValueCount(60);

    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);

    mChart.setDrawGridBackground(false);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setDrawGridLines(false);
    xAxis.setSpaceBetweenLabels(2);

    ValueFormatter custom = new MyValueFormatter();

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setLabelCount(8, false);
    leftAxis.setValueFormatter(custom);
    leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
    leftAxis.setSpaceTop(15f);

    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setDrawGridLines(false);
    rightAxis.setLabelCount(8, false);
    rightAxis.setValueFormatter(custom);
    rightAxis.setSpaceTop(15f);

    Legend l = mChart.getLegend();
    l.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT);
    l.setForm(Legend.LegendForm.SQUARE);
    l.setFormSize(9f);
    l.setTextSize(11f);
    l.setXEntrySpace(4f);

    return barChartLayout;
  }
Пример #7
0
  public HorizontalBarChart setupHorizontalChartGastos(HorizontalBarChart mChart) {
    mChart.setDrawBarShadow(false);

    mChart.setDrawValueAboveBar(true);

    mChart.setDescription("");

    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    mChart.setMaxVisibleValueCount(60);

    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);

    // draw shadows for each bar that show the maximum value
    // mChart.setDrawBarShadow(true);

    // mChart.setDrawXLabels(false);

    mChart.setDrawGridBackground(false);

    // mChart.setDrawYLabels(false);

    XAxis xl = mChart.getXAxis();
    xl.setPosition(XAxis.XAxisPosition.BOTTOM);
    xl.setTypeface(tf);
    xl.setDrawAxisLine(true);
    xl.setDrawGridLines(true);
    xl.setGridLineWidth(0.3f);

    YAxis yl = mChart.getAxisLeft();
    yl.setTypeface(tf);
    yl.setDrawAxisLine(true);
    yl.setDrawGridLines(true);
    yl.setGridLineWidth(0.3f);
    //        yl.setInverted(true);

    YAxis yr = mChart.getAxisRight();
    yr.setTypeface(tf);
    yr.setDrawAxisLine(true);
    yr.setDrawGridLines(false);
    //        yr.setInverted(true);
    Legend l = mChart.getLegend();
    l.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT);
    l.setFormSize(8f);
    l.setXEntrySpace(4f);

    return mChart;
  }
Пример #8
0
 /** Define the design of the chart. */
 private void prepareChart() {
   // Chart
   chart1 = (BarChart) view.findViewById(R.id.chart1);
   chart1.setMaxVisibleValueCount(60);
   chart1.setDrawGridBackground(false);
   chart1.setDescription("");
   chart1.setNoDataTextDescription("Select the range of dates...");
   // X axis
   XAxis xAxis = chart1.getXAxis();
   xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
   xAxis.setDrawGridLines(false);
   // Y axis
   YAxisValueFormatter custom = new MyYAxisValueFormatter();
   YAxis leftAxis = chart1.getAxisLeft();
   leftAxis.setLabelCount(8, false);
   leftAxis.setValueFormatter(custom);
   leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
   leftAxis.setSpaceTop(15f);
   YAxis rightAxis = chart1.getAxisRight();
   rightAxis.setDrawGridLines(false);
   rightAxis.setLabelCount(8, false);
   rightAxis.setValueFormatter(custom);
   rightAxis.setSpaceTop(15f);
   // Legend
   Legend l = chart1.getLegend();
   l.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT);
   l.setForm(Legend.LegendForm.CIRCLE);
   l.setFormSize(9f);
   l.setTextSize(11f);
   l.setXEntrySpace(4f);
   // Initialize chart without data
   ArrayList<BarEntry> entries = new ArrayList<>();
   BarDataSet dataset = new BarDataSet(entries, "" + maxDate.get(YEAR));
   ArrayList<String> labels = new ArrayList<>();
   BarData data = new BarData(labels, dataset);
   chart1.setData(data);
 }
Пример #9
0
  private void initChart() {
    barChart.setDrawBorders(true);
    barChart.setBorderWidth(1);
    barChart.setBorderColor(getResources().getColor(R.color.minute_grayLine));
    barChart.setDescription("");
    barChart.setDragEnabled(true);
    barChart.setScaleYEnabled(false);

    Legend barChartLegend = barChart.getLegend();
    barChartLegend.setEnabled(false);

    // BarYAxisFormatter  barYAxisFormatter=new BarYAxisFormatter();
    // bar x y轴
    xAxisBar = barChart.getXAxis();
    xAxisBar.setDrawLabels(true);
    xAxisBar.setDrawGridLines(false);
    xAxisBar.setDrawAxisLine(false);
    xAxisBar.setTextColor(getResources().getColor(R.color.minute_zhoutv));
    xAxisBar.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxisBar.setGridColor(getResources().getColor(R.color.minute_grayLine));

    axisLeftBar = barChart.getAxisLeft();
    axisLeftBar.setAxisMinValue(0);
    axisLeftBar.setDrawGridLines(false);
    axisLeftBar.setDrawAxisLine(false);
    axisLeftBar.setTextColor(getResources().getColor(R.color.minute_zhoutv));
    axisLeftBar.setDrawLabels(true);
    axisLeftBar.setSpaceTop(0);
    axisLeftBar.setShowOnlyMinMax(true);
    axisRightBar = barChart.getAxisRight();
    axisRightBar.setDrawLabels(false);
    axisRightBar.setDrawGridLines(false);
    axisRightBar.setDrawAxisLine(false);
    /** ************************************************************* */
    combinedchart.setDrawBorders(true);
    combinedchart.setBorderWidth(1);
    combinedchart.setBorderColor(getResources().getColor(R.color.minute_grayLine));
    combinedchart.setDescription("");
    combinedchart.setDragEnabled(true);
    combinedchart.setScaleYEnabled(false);

    Legend combinedchartLegend = combinedchart.getLegend();
    combinedchartLegend.setEnabled(false);
    // bar x y轴
    xAxisK = combinedchart.getXAxis();
    xAxisK.setDrawLabels(true);
    xAxisK.setDrawGridLines(false);
    xAxisK.setDrawAxisLine(false);
    xAxisK.setTextColor(getResources().getColor(R.color.minute_zhoutv));
    xAxisK.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxisK.setGridColor(getResources().getColor(R.color.minute_grayLine));

    axisLeftK = combinedchart.getAxisLeft();
    axisLeftK.setDrawGridLines(true);
    axisLeftK.setDrawAxisLine(false);
    axisLeftK.setDrawLabels(true);
    axisLeftK.setTextColor(getResources().getColor(R.color.minute_zhoutv));
    axisLeftK.setGridColor(getResources().getColor(R.color.minute_grayLine));
    axisLeftK.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
    axisRightK = combinedchart.getAxisRight();
    axisRightK.setDrawLabels(false);
    axisRightK.setDrawGridLines(true);
    axisRightK.setDrawAxisLine(false);
    axisRightK.setGridColor(getResources().getColor(R.color.minute_grayLine));
    combinedchart.setDragDecelerationEnabled(true);
    barChart.setDragDecelerationEnabled(true);
    combinedchart.setDragDecelerationFrictionCoef(0.2f);
    barChart.setDragDecelerationFrictionCoef(0.2f);

    // 将K线控的滑动事件传递给交易量控件
    combinedchart.setOnChartGestureListener(
        new CoupleChartGestureListener(combinedchart, new Chart[] {barChart}));
    // 将交易量控件的滑动事件传递给K线控件
    barChart.setOnChartGestureListener(
        new CoupleChartGestureListener(barChart, new Chart[] {combinedchart}));
    barChart.setOnChartValueSelectedListener(
        new OnChartValueSelectedListener() {
          @Override
          public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
            Log.e("%%%%", h.getXIndex() + "");
            combinedchart.highlightValues(new Highlight[] {h});
          }

          @Override
          public void onNothingSelected() {
            combinedchart.highlightValue(null);
          }
        });
    combinedchart.setOnChartValueSelectedListener(
        new OnChartValueSelectedListener() {
          @Override
          public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {

            barChart.highlightValues(new Highlight[] {h});
          }

          @Override
          public void onNothingSelected() {
            barChart.highlightValue(null);
          }
        });
  }
Пример #10
0
  @Override
  public View getView(int position, View convertView, Context c) {

    ViewHolder holder = null;

    if (convertView == null) {

      holder = new ViewHolder();

      convertView = LayoutInflater.from(c).inflate(R.layout.list_item_linechart, null);
      holder.chart = (LineChart) convertView.findViewById(R.id.chart);

      convertView.setTag(holder);

    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    // apply styling
    // holder.chart.setValueTypeface(mTf);
    holder.chart.setDescription("");
    holder.chart.setDrawGridBackground(false);

    XAxis xAxis = holder.chart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTTOM);
    xAxis.setTypeface(mTf);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(true);

    YAxis leftAxis = holder.chart.getAxisLeft();
    leftAxis.setTypeface(mTf);
    leftAxis.setLabelCount(5, false);

    YAxis rightAxis = holder.chart.getAxisRight();
    rightAxis.setTypeface(mTf);
    rightAxis.setLabelCount(5, false);
    rightAxis.setDrawGridLines(false);

    // set data
    holder.chart.setData((LineData) mChartData);

    // do not forget to refresh the chart
    // holder.chart.invalidate();
    holder.chart.animateX(750);
    // at 20151130
    // at 20151117
    //        if(mType==0) {
    //        	LimitLine ll = new LimitLine(30, "目标温度");
    //        	ll.setLineWidth(4f);
    //        	ll.enableDashedLine(10f, 10f, 0f);
    //        	ll.setLabelPosition(LimitLabelPosition.LEFT_BOTTOM);
    //        	ll.setTextSize(10f);
    //        	leftAxis.addLimitLine(ll);
    //        } else {
    //            LimitLine ll = new LimitLine(60, "目标湿度");
    //            ll.setLineWidth(4f);
    //            ll.enableDashedLine(10f, 10f, 0f);
    //            ll.setLabelPosition(LimitLabelPosition.LEFT_BOTTOM);
    //            ll.setTextSize(10f);
    //            leftAxis.addLimitLine(ll);
    //        }

    // end 20151117
    LimitLine ll = new LimitLine(this.aimValue, this.aimName);
    ll.setLineWidth(4f);
    ll.enableDashedLine(10f, 10f, 0f);
    ll.setLabelPosition(LimitLabelPosition.LEFT_BOTTOM);
    ll.setTextSize(10f);
    leftAxis.addLimitLine(ll);
    // end 20151130
    return convertView;
  }
Пример #11
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    rootView = inflater.inflate(R.layout.kommfort, container, false);
    RelativeLayout relativ = (RelativeLayout) rootView.findViewById(R.id.bak);

    mLineChart = (LineChart) relativ.findViewById(R.id.linechartkommfort);
    mLineChart.setOnChartValueSelectedListener(this);

    // no description text
    mLineChart.setDescription("Beschleunigungskraefte");
    mLineChart.setNoDataTextDescription("You need to provide data for the chart.");

    // enable highlighting
    mLineChart.setHighlightEnabled(true);

    // enable touch gestures
    mLineChart.setTouchEnabled(true);

    // enable scaling and dragging
    mLineChart.setDragEnabled(true);
    mLineChart.setScaleEnabled(true);
    mLineChart.setDrawGridBackground(false);

    // if disabled, scaling can be done on x- and y-axis separately
    mLineChart.setPinchZoom(true);

    // set an alternative background color
    mLineChart.setBackgroundColor(Color.WHITE);

    LineData data = new LineData();
    data.setValueTextColor(Color.BLACK);

    // add empty data
    mLineChart.setData(data);

    // get the legend (only possible after setting data)
    Legend l = mLineChart.getLegend();

    // modify the legend ...
    // l.setPosition(LegendPosition.LEFT_OF_CHART);
    l.setForm(Legend.LegendForm.LINE);

    l.setTextColor(Color.BLACK);

    XAxis xl = mLineChart.getXAxis();

    xl.setTextColor(Color.BLACK);
    xl.setDrawGridLines(false);
    xl.setAvoidFirstLastClipping(true);

    YAxis leftAxis = mLineChart.getAxisLeft();

    leftAxis.setTextColor(Color.BLACK);
    leftAxis.setAxisMaxValue(2f);
    leftAxis.setAxisMinValue(-2f);
    leftAxis.setStartAtZero(false);
    leftAxis.setDrawGridLines(true);

    YAxis rightAxis = mLineChart.getAxisRight();
    rightAxis.setEnabled(false);

    Button zukamm = (Button) rootView.findViewById(R.id.butonzumkreis);
    // TextView zubesh=(TextView) rootView.findViewById(R.id.zubeschleunigungskraefte);

    // Layout button=(Layout) rootView.findViewById(R.id.);

    zukamm.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(getActivity(), KammsherKreis.class);
            Kommfort.this.startActivity(intent);
          }
        });

    /**
     * zubesh.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) {
     * Intent myIntent = new Intent(getActivity(), Beschleunigungskraefte.class);
     * getActivity().startActivityForResult(myIntent,100); } });
     */
    return rootView;
  }
  private void setChart(BarChart barChart, double[][] values, String[] labels) {

    int[] colors = new int[5];
    colors[0] = Color.argb(255, 11, 55, 144);
    colors[1] = Color.argb(255, 48, 120, 254);
    colors[2] = Color.argb(255, 123, 179, 254);
    colors[3] = Color.argb(255, 230, 230, 230);
    colors[4] = Color.argb(0, 255, 255, 255);

    ArrayList<BarEntry> dataEntries = new ArrayList<BarEntry>();

    for (int i = 0; i < values.length; ++i) {
      float[] fList = new float[values[i].length];

      for (int j = 0; j < values[i].length; ++j) {
        fList[j] = (float) values[i][j];
      }

      dataEntries.add(new BarEntry(fList, i));
    }
    BarDataSet dataSet = new BarDataSet(dataEntries, "");
    dataSet.setBarSpacePercent(2f);
    dataSet.setStackLabels(new String[] {"浅睡眠", "深睡眠", "活动"});
    dataSet.setColors(new int[] {colors[0], colors[1], colors[2]});

    dataSet.setDrawValues(false);
    ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
    dataSets.add(dataSet);
    BarData barData = new BarData(labels, dataSets);
    barChart.setData(barData);

    YAxis leftAxis = barChart.getAxisLeft();
    leftAxis.setDrawGridLines(true);
    leftAxis.setDrawLabels(false);
    leftAxis.setGridColor(colors[3]);
    leftAxis.setDrawAxisLine(true);
    leftAxis.setAxisLineColor(colors[3]);
    leftAxis.setAxisLineWidth(0.5f);
    YAxis rightAxis = barChart.getAxisRight();
    rightAxis.setEnabled(true);
    rightAxis.setDrawLabels(false);
    rightAxis.setDrawGridLines(false);
    rightAxis.setAxisLineColor(colors[3]);
    rightAxis.setAxisLineWidth(0.5f);

    XAxis xAxis = barChart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTTOM);
    xAxis.setDrawLabels(false);
    xAxis.setDrawGridLines(true);
    xAxis.setGridColor(colors[3]);
    xAxis.setAxisLineWidth(0.5f);
    xAxis.setAxisLineColor(colors[3]);

    barChart.setBackgroundColor(colors[4]);
    barChart.setGridBackgroundColor(colors[4]);
    barChart.getLegend().setEnabled(false);
    barChart.setScaleEnabled(false);
    barChart.setDescription("");
    barChart.animateXY(2000, 2000);
    barChart.notifyDataSetChanged();
  }
Пример #13
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //        setContentView(R.layout.activity_realtime_chart);
    //        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    //        setSupportActionBar(toolbar);

    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_realtime_chart);

    //        mChart = (LineChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);

    mChart.setDescription("Sleep Cycle live chart");
    mChart.setNoDataTextDescription("No sleep data available.");

    mChart.setTouchEnabled(true);

    mChart.setDragEnabled(true);
    mChart.setScaleEnabled(true);

    mChart.setPinchZoom(true);

    LineData data = new LineData();

    mChart.setData(data);

    Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

    Legend l = mChart.getLegend();
    l.setForm(Legend.LegendForm.LINE);
    l.setTypeface(tf);
    l.setTextColor(Color.WHITE);

    XAxis xl = mChart.getXAxis();
    xl.setTypeface(tf);
    xl.setTextColor(Color.WHITE);
    xl.setDrawGridLines(false);
    xl.setAvoidFirstLastClipping(true);
    xl.setSpaceBetweenLabels(5);
    xl.setEnabled(true);

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(tf);
    leftAxis.setTextColor(Color.WHITE);
    leftAxis.setAxisMaxValue(100f);
    leftAxis.setAxisMinValue(0f);
    leftAxis.setStartAtZero(false);
    leftAxis.setDrawGridLines(true);

    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setEnabled(false);

    //        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    //        fab.setOnClickListener(new View.OnClickListener() {
    //            @Override
    //            public void onClick(View view) {
    //                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
    //                        .setAction("Action", null).show();
    //            }
    //        });
  }
  protected void onCreate(Bundle savedInstanceState) {

    setLayout(R.layout.activity_rfdroid);
    super.onCreate(savedInstanceState);

    registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter());

    UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);

    deviceFoundDialog =
        ProgressDialog.show(
            RFdroidActivity.this,
            "",
            getResources().getString(R.string.toast_looking_for_rfdroid),
            true);
    deviceFoundDialog.setCancelable(false);
    deviceFoundDialog.setOnKeyListener(
        new DialogInterface.OnKeyListener() {
          @Override
          public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
              dialog.dismiss();
              onBackPressed();
              return true;
            }
            return false;
          }
        });

    final ScrollView view = (ScrollView) findViewById(R.id.scrollview);
    view.getViewTreeObserver()
        .addOnScrollChangedListener(
            new ViewTreeObserver.OnScrollChangedListener() {
              @Override
              public void onScrollChanged() {
                if (!openingDrawer) {
                  if (view.getScrollX() == 0 && view.getScrollY() == 0) {
                    discreteSeekBar.showFloater(250);
                  } else {
                    discreteSeekBar.hideFloater(1);
                  }
                }
              }
            });

    sharedpreferences = getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE);
    int dataChartTypeVal =
        sharedpreferences.getInt("dataChartType", DataChartType.RECEPTION_RATE.ordinal());

    if (dataChartTypeVal == DataChartType.PACKET_NUMBER.ordinal()) {
      dataChartType = DataChartType.PACKET_NUMBER;
    }

    tablelayout = (TableLayout) findViewById(R.id.tablelayout);

    altTableRow(2);

    mChart = (BarChart) findViewById(R.id.chart1);

    mChart.setDrawBarShadow(false);
    mChart.setDrawValueAboveBar(true);

    mChart.setDescription("");

    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    mChart.setMaxVisibleValueCount(60);

    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);

    mChart.setDrawGridBackground(false);
    mChart.setDescriptionColor(Color.parseColor("#000000"));

    XAxis xAxis = mChart.getXAxis();
    xAxis.setDrawGridLines(false);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setSpaceBetweenLabels(0);

    YAxisValueFormatter custom = new DataAxisFormatter("%");

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setValueFormatter(custom);
    leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);

    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setValueFormatter(custom);
    rightAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);

    leftAxis.setDrawGridLines(true);
    rightAxis.setDrawGridLines(false);

    mChart.animateY(1000);

    mChart.getLegend().setEnabled(true);

    mChart.setVisibility(View.GONE);

    discreteSeekBar = (DiscreteSeekBar) findViewById(R.id.discrete1);
    discreteSeekBar.keepShowingPopup(true);

    discreteSeekBar.setNumericTransformer(
        new DiscreteSeekBar.NumericTransformer() {
          @Override
          public int transform(int value) {
            return value * 5;
          }
        });

    discreteSeekBar.setOnFocusChangeListener(
        new View.OnFocusChangeListener() {
          @Override
          public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
              discreteSeekBar.showFloater(250);
            }
          }
        });

    discreteSeekBar.setOnProgressChangeListener(
        new DiscreteSeekBar.OnProgressChangeListener() {

          @Override
          public void onProgressChanged(DiscreteSeekBar seekBar, int value, boolean fromUser) {}

          @Override
          public void onStartTrackingTouch(DiscreteSeekBar seekBar) {}

          @Override
          public void onStopTrackingTouch(DiscreteSeekBar seekBar) {
            setAdvertisingInteval();
          }
        });

    if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {

      discreteSeekBar.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              setAdvertisingInteval();
            }
          });
    }

    intervalTv = (TextView) findViewById(R.id.interval_head);
    globalReceptionRateTv = (TextView) findViewById(R.id.global_reception_rate);
    lastPacketReceivedTv = (TextView) findViewById(R.id.last_packet_received_value);
    samplingTimeTv = (TextView) findViewById(R.id.sampling_time_value);
    totalPacketReceiveTv = (TextView) findViewById(R.id.total_packet_received_value);
    averagePacketReceivedTv = (TextView) findViewById(R.id.average_packet_received_value);

    initTv();

    if (mBluetoothAdapter.isEnabled()) {
      Intent intent = new Intent(this, BtAnalyzerService.class);
      mBound = bindService(intent, mServiceConnection, BIND_AUTO_CREATE);
    }
  }