com.github.mikephil.charting.charts.BarChart类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(15.0k)|赞(0)|评价(0)|浏览(1192)

本文整理了Java中com.github.mikephil.charting.charts.BarChart类的一些代码示例,展示了BarChart类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BarChart类的具体详情如下:
包路径:com.github.mikephil.charting.charts.BarChart
类名称:BarChart

BarChart介绍

[英]Chart that draws bars.
[中]绘制条形图的图表。

代码示例

代码示例来源:origin: PhilJay/MPAndroidChart

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);

代码示例来源:origin: PhilJay/MPAndroidChart

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);

代码示例来源:origin: PhilJay/MPAndroidChart

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();

代码示例来源:origin: PhilJay/MPAndroidChart

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

代码示例来源:origin: PhilJay/MPAndroidChart

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

代码示例来源:origin: PhilJay/MPAndroidChart

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

代码示例来源:origin: thuryn/your-local-weather

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));

代码示例来源:origin: WJKCharlie/MPAndroidChartTest

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();

代码示例来源:origin: PhilJay/MPAndroidChart

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);

代码示例来源:origin: PhilJay/MPAndroidChart

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

代码示例来源:origin: PhilJay/MPAndroidChart

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);

代码示例来源:origin: SecUSo/privacy-friendly-netmonitor

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();

代码示例来源:origin: xiaolongonly/Ticket-Analysis

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

代码示例来源:origin: PhilJay/MPAndroidChart

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);

代码示例来源:origin: WenWangAndroid/ChartManager

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();

代码示例来源:origin: PhilJay/MPAndroidChart

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

代码示例来源:origin: WJKCharlie/MPAndroidChartTest

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);

代码示例来源:origin: xiaolongonly/Ticket-Analysis

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);

代码示例来源:origin: survivingwithandroid/Surviving-with-android

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

代码示例来源:origin: zhuanghongji/mp-android-chart

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

相关文章

微信公众号

最新文章

更多