Java Code Examples for com.github.mikephil.charting.charts.BarChart#setData()
The following examples show how to use
com.github.mikephil.charting.charts.BarChart#setData() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BarChartFrag.java From StockChart-MPAndroidChart with MIT License | 5 votes |
@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; }
Example 2
Source File: BarChartFrag.java From Stayfit with Apache License 2.0 | 5 votes |
@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); leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true) 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; }
Example 3
Source File: ChartActivity.java From Stayfit with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chart); BarChart chart = (BarChart) findViewById(R.id.chart); BarData data = new BarData(); chart.setData(data); chart.setDescription("My Chart"); chart.animateXY(2000, 2000); chart.invalidate(); }
Example 4
Source File: MeasurementActivity.java From NoiseCapture with GNU General Public License v3.0 | 5 votes |
private void updateSpectrumGUI() { ArrayList<String> xVals = new ArrayList<String>(); ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>(); double[] freqLabels = measurementService.getAudioProcess().getRealtimeCenterFrequency(); float[] freqValues = measurementService.getAudioProcess().getThirdOctaveFrequencySPL(); for(int idfreq =0; idfreq < freqLabels.length; idfreq++) { xVals.add(Spectrogram.formatFrequency((int)freqLabels[idfreq])); // Sum values // Compute frequency range covered by frequency yVals1.add(new BarEntry(new float[] {freqValues[idfreq]}, idfreq)); } BarDataSet set1 = new BarDataSet(yVals1, "DataSet"); set1.setColor(Color.rgb(102, 178, 255)); set1.setStackLabels(new String[]{ "SL" }); ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>(); dataSets.add(set1); BarData data = new BarData(xVals, dataSets); data.setValueTextSize(10f); BarChart sChart = getSpectrum(); if(sChart != null){ sChart.setData(data); sChart.setPadding(0, 0, 0, 0); sChart.setViewPortOffsets(0,0,0,0); sChart.invalidate(); // refresh } }
Example 5
Source File: MainActivity.java From Machine-Learning-Projects-for-Mobile-Applications with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load the model and labels. try { classifier = new DigitClassifierModel(this); } catch (IOException e) { Log.e(TAG, "Failed to initialize an image classifier.", e); } //startBackgroundThread(); setContentView(R.layout.activity_main); paintView = (FreeHandView) findViewById(R.id.paintView); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); BarChart barChart = (BarChart) findViewById(R.id.barChart); barChart.animateY(3000); barChart.getXAxis().setEnabled(true); barChart.getAxisRight().setEnabled(false); barChart.getAxisLeft().setAxisMinimum(0.0f); // start at zero barChart.getAxisLeft().setAxisMaximum(1.0f); // the axis maximum is 100 barChart.getDescription().setEnabled(false); barChart.getLegend().setEnabled(false); // the labels that should be drawn on the XAxis final String[] barLabels = new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; IAxisValueFormatter formatter = new IAxisValueFormatter() { @Override public String getFormattedValue(float value, AxisBase axis) { return barLabels[(int) value]; } }; barChart.getXAxis().setGranularity(0f); // minimum axis-step (interval) is 1 barChart.getXAxis().setValueFormatter(formatter); barChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM); barChart.getXAxis().setTextSize(5f); BARENTRY = new ArrayList<>(); initializeBARENTRY(); Bardataset = new BarDataSet(BARENTRY, "project"); BARDATA = new BarData(Bardataset); barChart.setData(BARDATA); paintView.init(metrics, classifier, barChart); Button resetButton = (Button) findViewById(R.id.resetButton); resetButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { paintView.clear(); } }); }
Example 6
Source File: HistogramChart.java From walt with Apache License 2.0 | 4 votes |
public HistogramChart(Context context, AttributeSet attrs) { super(context, attrs); inflate(getContext(), R.layout.histogram, this); barChart = (BarChart) findViewById(R.id.bar_chart); findViewById(R.id.button_close_bar_chart).setOnClickListener(this); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HistogramChart); final String descString; final int numDataSets; final float binWidth; try { descString = a.getString(R.styleable.HistogramChart_description); numDataSets = a.getInteger(R.styleable.HistogramChart_numDataSets, 1); binWidth = a.getFloat(R.styleable.HistogramChart_binWidth, 5f); } finally { a.recycle(); } ArrayList<IBarDataSet> dataSets = new ArrayList<>(numDataSets); for (int i = 0; i < numDataSets; i++) { final BarDataSet dataSet = new BarDataSet(new ArrayList<BarEntry>(), ""); dataSet.setColor(ColorTemplate.MATERIAL_COLORS[i]); dataSets.add(dataSet); } BarData barData = new BarData(dataSets); barData.setBarWidth((1f - GROUP_SPACE)/numDataSets); barChart.setData(barData); histogramData = new HistogramData(numDataSets, binWidth); groupBars(barData); final Description desc = new Description(); desc.setText(descString); desc.setTextSize(12f); barChart.setDescription(desc); XAxis xAxis = barChart.getXAxis(); xAxis.setGranularityEnabled(true); xAxis.setGranularity(1); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setValueFormatter(new IAxisValueFormatter() { DecimalFormat df = new DecimalFormat("#.##"); @Override public String getFormattedValue(float value, AxisBase axis) { return df.format(histogramData.getDisplayValue(value)); } }); barChart.setFitBars(true); barChart.invalidate(); }
Example 7
Source File: CalibrationLinearityActivity.java From NoiseCapture with GNU General Public License v3.0 | 4 votes |
private void updateBarChart() { BarChart barChart = getBarChart(); if(barChart == null) { return; } if(freqLeqStats.size() <= 2) { return; } double[] pearsons = computePearson(); if(pearsons == null) { return; } float YMin = Float.MAX_VALUE; float YMax = Float.MIN_VALUE; ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>(); // Read all white noise values for indexing before usage ArrayList<BarEntry> yMeasure = new ArrayList<BarEntry>(); int idfreq = 0; for (double value : pearsons) { YMax = Math.max(YMax, (float)value); YMin = Math.min(YMin, (float)value); yMeasure.add(new BarEntry((float)value, idfreq++)); } BarDataSet freqSet = new BarDataSet(yMeasure, "Pearson's correlation"); freqSet.setColor(ColorTemplate.COLORFUL_COLORS[0]); freqSet.setValueTextColor(Color.WHITE); freqSet.setDrawValues(true); dataSets.add(freqSet); ArrayList<String> xVals = new ArrayList<String>(); double[] freqs = FFTSignalProcessing.computeFFTCenterFrequency(AudioProcess.REALTIME_SAMPLE_RATE_LIMITATION); for (double freqValue : freqs) { xVals.add(Spectrogram.formatFrequency((int)freqValue)); } // create a data object with the datasets BarData data = new BarData(xVals, dataSets); barChart.setData(data); YAxis yl = barChart.getAxisLeft(); yl.setAxisMinValue(YMin - 0.1f); yl.setAxisMaxValue(YMax + 0.1f); barChart.invalidate(); }