chart.setOnChartValueSelectedListener(this); chart.getDescription().setEnabled(false); chart.setMaxVisibleValueCount(40); chart.setPinchZoom(false); chart.setDrawGridBackground(false); chart.setDrawBarShadow(false); chart.setDrawValueAboveBar(false); chart.setHighlightFullBarEnabled(false); YAxis leftAxis = chart.getAxisLeft(); leftAxis.setValueFormatter(new MyValueFormatter("K")); leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true) chart.getAxisRight().setEnabled(false); XAxis xLabels = chart.getXAxis(); xLabels.setPosition(XAxisPosition.TOP); seekBarY.setProgress(100); Legend l = chart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
holder.chart.getDescription().setEnabled(false); holder.chart.setDrawGridBackground(false); holder.chart.setDrawBarShadow(false); XAxis xAxis = holder.chart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTTOM); xAxis.setTypeface(mTf); xAxis.setDrawAxisLine(true); YAxis leftAxis = holder.chart.getAxisLeft(); leftAxis.setTypeface(mTf); leftAxis.setLabelCount(5, false); leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true) YAxis rightAxis = holder.chart.getAxisRight(); rightAxis.setTypeface(mTf); rightAxis.setLabelCount(5, false); holder.chart.setData((BarData) mChartData); holder.chart.setFitBars(true); holder.chart.animateY(700);
if (chart.getData() != null && chart.getData().getDataSetCount() > 0) { set1 = (BarDataSet) chart.getData().getDataSetByIndex(0); set2 = (BarDataSet) chart.getData().getDataSetByIndex(1); set3 = (BarDataSet) chart.getData().getDataSetByIndex(2); set4 = (BarDataSet) chart.getData().getDataSetByIndex(3); set1.setValues(values1); set2.setValues(values2); set3.setValues(values3); set4.setValues(values4); chart.getData().notifyDataChanged(); chart.notifyDataSetChanged(); data.setValueTypeface(tfLight); chart.setData(data); chart.getBarData().setBarWidth(barWidth); chart.getXAxis().setAxisMinimum(startYear); chart.getXAxis().setAxisMaximum(startYear + chart.getBarData().getGroupWidth(groupSpace, barSpace) * groupCount); chart.groupBars(startYear, groupSpace, barSpace); chart.invalidate();
/** * Groups all BarDataSet objects this data object holds together by modifying the x-value of their entries. * Previously set x-values of entries will be overwritten. Leaves space between bars and groups as specified * by the parameters. * Calls notifyDataSetChanged() afterwards. * * @param fromX the starting point on the x-axis where the grouping should begin * @param groupSpace the space between groups of bars in values (not pixels) e.g. 0.8f for bar width 1f * @param barSpace the space between individual bars in values (not pixels) e.g. 0.1f for bar width 1f */ public void groupBars(float fromX, float groupSpace, float barSpace) { if (getBarData() == null) { throw new RuntimeException("You need to set data for the chart before grouping bars."); } else { getBarData().groupBars(fromX, groupSpace, barSpace); notifyDataSetChanged(); } } }
@Override public void onValueSelected(Entry e, Highlight h) { if (e == null) return; RectF bounds = onValueSelectedRectF; chart.getBarBounds((BarEntry) e, bounds); MPPointF position = chart.getPosition(e, AxisDependency.LEFT); Log.i("bounds", bounds.toString()); Log.i("position", position.toString()); Log.i("x-index", "low: " + chart.getLowestVisibleX() + ", high: " + chart.getHighestVisibleX()); MPPointF.recycleInstance(position); }
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.frag_simple_bar, container, false); // create a new chart object chart = new BarChart(getActivity()); chart.getDescription().setEnabled(false); chart.setOnChartGestureListener(this); MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view); mv.setChartView(chart); // For bounds control chart.setMarker(mv); chart.setDrawGridBackground(false); chart.setDrawBarShadow(false); Typeface tf = Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf"); chart.setData(generateBarData(1, 20000, 12)); Legend l = chart.getLegend(); l.setTypeface(tf); YAxis leftAxis = chart.getAxisLeft(); leftAxis.setTypeface(tf); leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true) chart.getAxisRight().setEnabled(false); XAxis xAxis = chart.getXAxis(); xAxis.setEnabled(false); // programmatically add the chart FrameLayout parent = v.findViewById(R.id.parentLayout); parent.addView(chart); return v; }
rainBarChart.setDescription(graphDescription); rainBarChart.setDrawGridBackground(false); rainBarChart.setTouchEnabled(true); rainBarChart.setDragEnabled(true); rainBarChart.setMaxHighlightDistance(300); rainBarChart.setPinchZoom(true); rainBarChart.getLegend().setEnabled(false); rainBarChart.setBackgroundColor(PreferenceUtil.getBackgroundColor(this)); rainBarChart.setGridBackgroundColor(PreferenceUtil.getTextColor(this)); XAxis x = rainBarChart.getXAxis(); x.setEnabled(true); x.setPosition(XAxis.XAxisPosition.BOTTOM); YAxis yLeft = rainBarChart.getAxisLeft(); yLeft.setEnabled(true); yLeft.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); rainBarChart.getAxisRight().setEnabled(false); if (rainBarChart.getData() != null) { rainBarChart.getData().removeDataSet(rainBarChart.getData().getDataSetByIndex( rainBarChart.getData().getDataSetCount() - 1)); set = new BarDataSet(entries, getString(R.string.graph_rain_label)); set.setValueTextSize(12f); rainBarChart.setData(data); } else { set = new BarDataSet(entries, getString(R.string.graph_rain_label));
barChart.getDescription().setEnabled(false);//设置描述 barChart.setPinchZoom(false);//设置不按比例放缩柱状图 barChart.setExtraBottomOffset(10); barChart.setExtraTopOffset(30); MPChartMarkerView markerView = new MPChartMarkerView(barChart.getContext(), R.layout.custom_marker_view); barChart.setMarker(markerView); XAxis xAxis = barChart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setGranularity(1f); YAxis leftAxis = barChart.getAxisLeft(); leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); leftAxis.setDrawGridLines(false); barChart.getAxisRight().setEnabled(false); Legend legend = barChart.getLegend(); legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER); legend.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); barChart.animateX(1500);//数据显示动画,从左往右依次显示 barChart.invalidate();
chart.setBackgroundColor(Color.WHITE); chart.setExtraTopOffset(-30f); chart.setExtraBottomOffset(10f); chart.setExtraLeftOffset(70f); chart.setExtraRightOffset(70f); chart.setDrawBarShadow(false); chart.setDrawValueAboveBar(true); chart.getDescription().setEnabled(false); chart.setPinchZoom(false); chart.setDrawGridBackground(false); XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTTOM); xAxis.setTypeface(tfRegular); YAxis left = chart.getAxisLeft(); left.setDrawLabels(false); left.setSpaceTop(25f); left.setZeroLineColor(Color.GRAY); left.setZeroLineWidth(0.7f); chart.getAxisRight().setEnabled(false); chart.getLegend().setEnabled(false);
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tvX.setText(String.valueOf(seekBarX.getProgress())); tvY.setText(String.valueOf(seekBarY.getProgress())); ArrayList<BarEntry> values = new ArrayList<>(); for (int i = 0; i < seekBarX.getProgress(); i++) { float multi = (seekBarY.getProgress() + 1); float val = (float) (Math.random() * multi) + multi / 3; values.add(new BarEntry(i, val)); } BarDataSet set1; if (chart.getData() != null && chart.getData().getDataSetCount() > 0) { set1 = (BarDataSet) chart.getData().getDataSetByIndex(0); set1.setValues(values); chart.getData().notifyDataChanged(); chart.notifyDataSetChanged(); } else { set1 = new BarDataSet(values, "Data Set"); set1.setColors(ColorTemplate.VORDIPLOM_COLORS); set1.setDrawValues(false); ArrayList<IBarDataSet> dataSets = new ArrayList<>(); dataSets.add(set1); BarData data = new BarData(dataSets); chart.setData(data); chart.setFitBars(true); } chart.invalidate(); }
for (IBarDataSet set : chart.getData().getDataSets()) set.setDrawValues(!set.isDrawValuesEnabled()); chart.invalidate(); break; if (chart.isPinchZoomEnabled()) chart.setPinchZoom(false); else chart.setPinchZoom(true); chart.invalidate(); break; chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); chart.notifyDataSetChanged(); break; for (IBarDataSet set : chart.getData().getDataSets()) ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); chart.invalidate(); break; if (chart.getData() != null) { chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); chart.animateX(2000);
XAxis xAxis = chart.getXAxis(); xAxis.setGranularity(1f); // minimum axis-step (interval) is 1 xAxis.setValueFormatter(formatter); YAxis yAxis_left = chart.getAxisLeft(); yAxis_left.setAxisMinimum(0f); YAxis yAxis_right = chart.getAxisRight(); yAxis_right.setAxisMinimum(0f); chart.setData(barData); chart.setFitBars(true); chart.setDescription(description); chart.invalidate();
@Override public void onGetHistoryRecentTicketListSuccess(List<TicketOpenData> list) { bcAvgAnalysis = BarChartHelper.getBarChartHelper().generateBarChartConfig(bcAvgAnalysis); BarData barData; if (bcAvgAnalysis.getData() != null && bcAvgAnalysis.getData().getDataSetCount() > 0) { barData = bcAvgAnalysis.getBarData(); for (int i = 0; i < barData.getDataSetCount(); i++) { BarDataSet barDataSet = (BarDataSet) barData.getDataSetByIndex(i); barDataSet.setValues(generateEntry(list)); } bcAvgAnalysis.getData().notifyDataChanged(); bcAvgAnalysis.notifyDataSetChanged(); } else { List<Integer> colorList = new ArrayList<>(); colorList.add(getResources().getColor(R.color.main_red_color)); colorList.add(getResources().getColor(R.color.main_blue_color_4c65ed)); IBarDataSet barDataSet = BarChartHelper.getBarChartHelper().generateBarDataSet(generateEntry(list), new String[]{"普通码", "特别码"}, colorList); barData = new BarData(barDataSet); bcAvgAnalysis.setData(barData); bcAvgAnalysis.getXAxis().setValueFormatter((value, axis) -> (int) value + "号"); bcAvgAnalysis.setMarker(new DataMarkView(this, (e, highlight) -> ((int) e.getX()) + "号:" + e.getY() + "次")); } bcAvgAnalysis.animateY(3000); }
chart.getDescription().setEnabled(false); chart.setMaxVisibleValueCount(60); chart.setPinchZoom(false); chart.setDrawBarShadow(false); chart.setDrawGridBackground(false); XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTTOM); xAxis.setDrawGridLines(false); chart.getAxisLeft().setDrawGridLines(false); chart.animateY(1500); chart.getLegend().setEnabled(false);
barChart.setBackgroundColor(Color.WHITE); barChart.setDrawGridBackground(false); barChart.setDrawBarShadow(false); barChart.setHighlightFullBarEnabled(false); barChart.setDoubleTapToZoomEnabled(false); barChart.setDragEnabled(false); barChart.setScaleXEnabled(false); barChart.setScaleYEnabled(false); barChart.setScaleEnabled(false); barChart.setDrawBorders(false); barChart.setDescription(description); barChart.animateY(1000, Easing.Linear); barChart.animateX(1000, Easing.Linear); xAxis = barChart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setGranularity(1f); leftAxis = barChart.getAxisLeft(); rightAxis = barChart.getAxisRight();
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_scrollview); setTitle("ScrollViewActivity"); chart = findViewById(R.id.chart1); chart.getDescription().setEnabled(false); // scaling can now only be done on x- and y-axis separately chart.setPinchZoom(false); chart.setDrawBarShadow(false); chart.setDrawGridBackground(false); XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTTOM); xAxis.setDrawGridLines(false); chart.getAxisLeft().setDrawGridLines(false); chart.getLegend().setEnabled(false); setData(10); chart.setFitBars(true); }
barChart.setDrawBarShadow(false); barChart.setDrawValueAboveBar(true); barChart.getDescription().setEnabled(false); barChart.setPinchZoom(false); barChart.setDrawGridBackground(false); barChart.setExtraBottomOffset(10); barChart.setExtraTopOffset(30); MPChartMarkerView markerView = new MPChartMarkerView(barChart.getContext(), R.layout.custom_marker_view); barChart.setMarker(markerView); XAxis xAxis = barChart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setDrawGridLines(false); YAxis left = barChart.getAxisLeft(); left.setDrawLabels(false); left.setSpaceTop(25f); left.setZeroLineColor(Color.DKGRAY); left.setZeroLineWidth(1f); barChart.getAxisRight().setEnabled(false); Legend legend = barChart.getLegend(); legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER); legend.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
public BarChart generateBarChartConfig(BarChart barChart) { XAxis xAxis = barChart.getXAxis(); YAxis yAxisRight = barChart.getAxisRight(); yAxisRight.setEnabled(false); YAxis yAxisLeft = barChart.getAxisLeft(); yAxisLeft.setAxisMinimum(0); barChart.setDrawBarShadow(false); barChart.setPinchZoom(true); barChart.setFitBars(true); barChart.setMaxVisibleValueCount(60); barChart.setDrawValueAboveBar(true); barChart.getDescription().setEnabled(false); barChart.setNoDataText("无数据"); Legend l = barChart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
private void initChartBar(BarChart chart) { chart.setTouchEnabled(true); chart.setDrawGridBackground(true); chart.getAxisRight().setEnabled(false); chart.setDrawGridBackground(true); YAxis leftAxis = chart.getAxisLeft(); leftAxis.setAxisMaxValue(100F); leftAxis.setAxisMinValue(10F); leftAxis.setStartAtZero(false); leftAxis.setAxisLineWidth(2); leftAxis.setDrawGridLines(true); // X-Axis XAxis xAxis = chart.getXAxis(); xAxis.resetLabelsToSkip(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setDrawGridLines(true); }
chart.setDescription("zhuanghongji"); chart.setDrawGridBackground(false);//设置网格背景 chart.setScaleEnabled(false);//设置缩放 chart.setDoubleTapToZoomEnabled(false);//设置双击不进行缩放 chart.setDrawValueAboveBar(true); XAxis xAxis = chart.getXAxis(); YAxis leftAxis = chart.getAxisLeft(); YAxis rightAxis = chart.getAxisRight(); rightAxis.setDrawAxisLine(false); // 右侧坐标轴线 rightAxis.setDrawLabels(false); // 右侧坐标轴数组Label