@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; }
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; }
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 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; }