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); }
/** * draws the x-labels on the specified y-position * * @param pos */ protected void drawLabels(Canvas c, float pos) { // pre allocate to save performance (dont allocate in loop) float[] position = new float[] {0f, 0f}; for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) { position[0] = i; mTrans.pointValuesToPixel(position); if (mViewPortHandler.isInBoundsX(position[0])) { String label = mXAxis.getValues().get(i); if (mXAxis.isAvoidFirstLastClippingEnabled()) { // avoid clipping of the last if (i == mXAxis.getValues().size() - 1 && mXAxis.getValues().size() > 1) { float width = Utils.calcTextWidth(mAxisLabelPaint, label); if (width > mViewPortHandler.offsetRight() * 2 && position[0] + width > mViewPortHandler.getChartWidth()) position[0] -= width / 2; // avoid clipping of the first } else if (i == 0) { float width = Utils.calcTextWidth(mAxisLabelPaint, label); position[0] += width / 2; } } c.drawText(label, position[0], pos, mAxisLabelPaint); } } }
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 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; }
/** * Draws the LimitLines associated with this axis to the screen. * * @param c */ @Override public void renderLimitLines(Canvas c) { List<LimitLine> limitLines = mXAxis.getLimitLines(); if (limitLines == null || limitLines.size() <= 0) return; float[] pts = new float[4]; Path limitLinePath = new Path(); for (int i = 0; i < limitLines.size(); i++) { LimitLine l = limitLines.get(i); pts[0] = l.getLimit(); pts[2] = l.getLimit(); mTrans.pointValuesToPixel(pts); pts[1] = mViewPortHandler.contentTop(); pts[3] = mViewPortHandler.contentBottom(); limitLinePath.moveTo(pts[0], pts[1]); limitLinePath.lineTo(pts[2], pts[3]); mLimitLinePaint.setStyle(Paint.Style.STROKE); mLimitLinePaint.setColor(l.getLineColor()); mLimitLinePaint.setStrokeWidth(l.getLineWidth()); mLimitLinePaint.setPathEffect(l.getDashPathEffect()); c.drawPath(limitLinePath, mLimitLinePaint); limitLinePath.reset(); String label = l.getLabel(); // if drawing the limit-value label is enabled if (label != null && !label.equals("")) { float xOffset = l.getLineWidth(); float add = Utils.convertDpToPixel(4f); mLimitLinePaint.setStyle(l.getTextStyle()); mLimitLinePaint.setPathEffect(null); mLimitLinePaint.setColor(l.getTextColor()); mLimitLinePaint.setStrokeWidth(0.5f); mLimitLinePaint.setTextSize(l.getTextSize()); float yOffset = Utils.calcTextHeight(mLimitLinePaint, label) + add / 2f; if (l.getLabelPosition() == LimitLine.LimitLabelPosition.POS_RIGHT) { c.drawText( label, pts[0] + xOffset, mViewPortHandler.contentBottom() - add, mLimitLinePaint); } else { c.drawText( label, pts[0] + xOffset, mViewPortHandler.contentTop() + yOffset, mLimitLinePaint); } } } }
@Override public void renderAxisLine(Canvas c) { if (!mXAxis.isDrawAxisLineEnabled() || !mXAxis.isEnabled()) return; mAxisLinePaint.setColor(mXAxis.getAxisLineColor()); mAxisLinePaint.setStrokeWidth(mXAxis.getAxisLineWidth()); // if (mXAxis.getPosition() == XAxisPosition.TOP // || mXAxis.getPosition() == XAxisPosition.TOP_INSIDE // || mXAxis.getPosition() == XAxisPosition.BOTH_SIDED) { c.drawLine( mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), mViewPortHandler.contentRight(), mViewPortHandler.contentTop(), mAxisLinePaint); // } // if (mXAxis.getPosition() == XAxisPosition.BOTTOM // || mXAxis.getPosition() == XAxisPosition.BOTTOM_INSIDE // || mXAxis.getPosition() == XAxisPosition.BOTH_SIDED) { c.drawLine( mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom() * topchartScale, mViewPortHandler.contentRight(), mViewPortHandler.contentBottom() * topchartScale, mAxisLinePaint); float yoffset = mViewPortHandler.contentBottom() * 0.08f - Utils.convertDpToPixel(1); c.drawLine( mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom() * topchartScale + yoffset, mViewPortHandler.contentRight(), mViewPortHandler.contentBottom() * topchartScale + yoffset, mAxisLinePaint); c.drawLine( mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom() - 1, mViewPortHandler.contentRight(), mViewPortHandler.contentBottom() - 1, mAxisLinePaint); // } }
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); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.frag_simple_bar, container, false); // create a new chart object mChart = new BarChart(getActivity()); mChart.setDescription(""); mChart.setOnChartGestureListener(this); MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view); mChart.setMarkerView(mv); mChart.setDrawGridBackground(false); mChart.setDrawBarShadow(false); Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), "OpenSans-Light.ttf"); mChart.setData(generateBarData(1, 20000, 12)); Legend l = mChart.getLegend(); l.setTypeface(tf); YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setTypeface(tf); mChart.getAxisRight().setEnabled(false); XAxis xAxis = mChart.getXAxis(); xAxis.setEnabled(false); // programatically add the chart FrameLayout parent = (FrameLayout) v.findViewById(R.id.parentLayout); parent.addView(mChart); return v; }
@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; }
/** 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); }
@Override public void renderAxisLabels(Canvas c) { if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled()) return; float yoffset = Utils.convertDpToPixel(4f); mAxisLabelPaint.setTypeface(mXAxis.getTypeface()); mAxisLabelPaint.setTextSize(mXAxis.getTextSize()); mAxisLabelPaint.setColor(mXAxis.getTextColor()); if (mXAxis.getPosition() == XAxisPosition.TOP) { drawLabels(c, mViewPortHandler.offsetTop() - yoffset); } else if (mXAxis.getPosition() == XAxisPosition.BOTTOM) { drawLabels( c, mViewPortHandler.contentBottom() * topchartScale + (mViewPortHandler.contentBottom() * 0.04f) + mXAxis.mLabelHeight / 2); } else if (mXAxis.getPosition() == XAxisPosition.BOTTOM_INSIDE) { drawLabels(c, mViewPortHandler.contentBottom() - yoffset); } else if (mXAxis.getPosition() == XAxisPosition.TOP_INSIDE) { drawLabels(c, mViewPortHandler.offsetTop() + yoffset + mXAxis.mLabelHeight); } else { // BOTH SIDED drawLabels(c, mViewPortHandler.offsetTop() - yoffset); drawLabels(c, mViewPortHandler.contentBottom() + mXAxis.mLabelHeight + yoffset * 1.6f); } }
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; }
public void computeAxis(float xValAverageLength, List<String> xValues) { mAxisLabelPaint.setTypeface(mXAxis.getTypeface()); mAxisLabelPaint.setTextSize(mXAxis.getTextSize()); StringBuffer a = new StringBuffer(); int max = (int) Math.round(xValAverageLength + mXAxis.getSpaceBetweenLabels()); for (int i = 0; i < max; i++) { a.append("h"); } mXAxis.mLabelWidth = Utils.calcTextWidth(mAxisLabelPaint, a.toString()); mXAxis.mLabelHeight = Utils.calcTextHeight(mAxisLabelPaint, "Q"); mXAxis.setValues(xValues); }
@Override public void renderGridLines(Canvas c) { if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled()) return; // pre alloc float[] position = new float[] {0f, 0f}; mGridPaint.setColor(mXAxis.getGridColor()); mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth()); mGridPaint.setPathEffect(mXAxis.getGridDashPathEffect()); Path gridLinePath = new Path(); for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) { String label = mXAxis.getValues().get(i); position[0] = i; mTrans.pointValuesToPixel(position); if (position[0] >= mViewPortHandler.offsetLeft() && position[0] <= mViewPortHandler.getChartWidth()) { gridLinePath.moveTo(position[0], mViewPortHandler.contentBottom() * topchartScale); gridLinePath.lineTo(position[0], mViewPortHandler.contentTop()); // draw a path because lines don't support dashing on lower android versions c.drawPath(gridLinePath, mGridPaint); } gridLinePath.reset(); if (position[0] >= mViewPortHandler.offsetLeft() && position[0] <= mViewPortHandler.getChartWidth()) { gridLinePath.moveTo( position[0], mViewPortHandler.contentBottom() * (topchartScale + 0.08f)); gridLinePath.lineTo(position[0], mViewPortHandler.contentBottom()); // draw a path because lines don't support dashing on lower android versions c.drawPath(gridLinePath, mGridPaint); } gridLinePath.reset(); } }
@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; }
public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LineView = inflater.inflate(R.layout.analysis_bar, container, false); initView(); // no description text mChart.setDescription(""); // enable value highlighting mChart.setHighlightEnabled(true); // enable touch gestures mChart.setTouchEnabled(true); // enable scaling and dragging mChart.setDragEnabled(true); mChart.setScaleEnabled(true); // if disabled, scaling can be done on x- and y-axis separately mChart.setPinchZoom(false); mChart.setDrawGridBackground(true); // tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); XAxis x = mChart.getXAxis(); // x.setTypeface(tf); x.setEnabled(true); YAxis y = mChart.getAxisLeft(); // y.setTypeface(tf); y.setLabelCount(5); y.setEnabled(true); mChart.getAxisRight().setEnabled(true); // add data catchData(); Date dt = new Date(); SimpleDateFormat matter1 = new SimpleDateFormat("dd"); int days = Integer.parseInt(matter1.format(dt)); log.e("days = " + days); setData(days - 9, 10, 100); mChart.getLegend().setEnabled(true); mChart.animateXY(2000, 2000); // dont forget to refresh the drawing /*ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData() .getDataSets(); for (LineDataSet set : sets) { if (set.isDrawCubicEnabled()) set.setDrawCubic(false); else set.setDrawCubic(true); }*/ mChart.invalidate(); return LineView; }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment final View view = inflater.inflate(R.layout.fragment_chart_tab, container, false); btnPrevious = (ImageButton) view.findViewById(R.id.btnPrevious); btnPrevious.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { convertExecutor.execute( new Runnable() { @Override public void run() { if (currentGraph <= 1) { return; } currentGraph--; ChartCollection collection = fromDevice ? fileManager.getCollection() : fileManager.getPcaCollection(); final Map<Double, Double> mapData = collection.getCharData(currentGraph - 1).getData(); // final double[] data = new // double[mapData.values().size()]; // // for (int i = 0; i < mapData.values().size(); i++) { // data[i] = mapData.get(i); // } mainHandler.post( new Runnable() { @Override public void run() { drawGraph(mapData); txtCurrent.setText(String.valueOf(currentGraph)); } }); } }); } }); btnNext = (ImageButton) view.findViewById(R.id.btnNext); btnNext.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { convertExecutor.execute( new Runnable() { @Override public void run() { if (currentGraph >= totalGraphs) { return; } currentGraph++; ChartCollection collection = fromDevice ? fileManager.getCollection() : fileManager.getPcaCollection(); final Map<Double, Double> mapData = collection.getCharData(currentGraph - 1).getData(); // final double[] data = new // double[mapData.values().size()]; // // for (int i = 0; i < mapData.values().size(); i++) { // data[i] = mapData.get(i); // } mainHandler.post( new Runnable() { @Override public void run() { drawGraph(mapData); txtCurrent.setText(String.valueOf(currentGraph)); } }); } }); } }); txtCurrent = (TextView) view.findViewById(R.id.txtCurrentGraph); txtTotal = (TextView) view.findViewById(R.id.txtTotalGraph); chart = (LineChart) view.findViewById(R.id.chart); chart.setNoDataText("Aguardando dados..."); chart.setScaleYEnabled(false); chart.setPinchZoom(true); if (fromDevice) { YAxis leftAxis = chart.getAxisLeft(); leftAxis.setAxisMinValue(0); leftAxis.setAxisMaxValue(100); } YAxis rightAxis = chart.getAxisRight(); rightAxis.setEnabled(false); XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); loadData(true); return view; }
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); } }
@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; }
@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(); // } // }); }
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); } }); }
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(); }