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 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; }
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); } }); }
@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; }
@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(); // } // }); }