Java Code Examples for com.github.mikephil.charting.data.BarDataSet#setColor()
The following examples show how to use
com.github.mikephil.charting.data.BarDataSet#setColor() .
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: BarChartActivitySinus.java From Stayfit with Apache License 2.0 | 6 votes |
private void setData(int count) { ArrayList<String> xVals = new ArrayList<String>(); ArrayList<BarEntry> entries = new ArrayList<BarEntry>(); for (int i = 0; i < count; i++) { xVals.add(i+""); entries.add(mSinusData.get(i)); } BarDataSet set = new BarDataSet(entries, "Sinus Function"); set.setBarSpacePercent(40f); set.setColor(Color.rgb(240, 120, 124)); BarData data = new BarData(xVals, set); data.setValueTextSize(10f); data.setValueTypeface(mTf); data.setDrawValues(false); mChart.setData(data); }
Example 2
Source File: MainActivity.java From AndroidDatabaseLibraryComparison with MIT License | 6 votes |
private void initChart() { ArrayList<BarDataSet> dataSets = new ArrayList<>(); // note that we show save first because that's how we initialize the DB for (String frameworkName : chartEntrySets.keySet()) { ArrayList<BarEntry> entrySet = chartEntrySets.get(frameworkName); BarDataSet dataSet = new BarDataSet(entrySet, frameworkName); dataSet.setColor(getFrameworkColor(frameworkName)); dataSets.add(dataSet); } // load data and animate it ArrayList<String> xAxisLabels = new ArrayList<>(); xAxisLabels.add("Save (msec)"); xAxisLabels.add("Load (msec)"); BarData data = new BarData(xAxisLabels, dataSets); chartView.setData(data); chartView.setDescription(null); // this takes up too much space, so clear it chartView.animateXY(2000, 2000); chartView.invalidate(); }
Example 3
Source File: StatisticsFragment.java From HeartBeat with Apache License 2.0 | 6 votes |
private BarData getWeekEventData() { BarData d = new BarData(); ArrayList<BarEntry> entries = new ArrayList<>(); for (int i=0; i<WEEK_COUNT; i++) { entries.add( new BarEntry( new GetCountSpecDayApi(getActivity()).exec( TimeUtils.calendarDaysBefore(WEEK_COUNT-i), GetCountSpecDayApi.EVENT ),i ) ); } BarDataSet set = new BarDataSet(entries, getString(R.string.event_count_text)); set.setColor(mPrimaryColorDark); set.setValueFormatter(new IntValueFormatter()); d.addDataSet(set); set.setAxisDependency(YAxis.AxisDependency.LEFT); return d; }
Example 4
Source File: MeasurementActivity.java From NoiseCapture with GNU General Public License v3.0 | 6 votes |
private void setData(double val) { ArrayList<String> xVals = new ArrayList<String>(); xVals.add(""); ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>(); yVals1.add(new BarEntry((float)val, 0)); BarDataSet set1 = new BarDataSet(yVals1, "DataSet"); //set1.setBarSpacePercent(35f); //set1.setColor(Color.rgb(0, 153, 204)); int nc=getNEcatColors(val); // Choose the color category in function of the sound level set1.setColor(NE_COLORS[nc]); ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>(); dataSets.add(set1); BarData data = new BarData(xVals, dataSets); data.setValueTextSize(10f); mChart.setData(data); mChart.invalidate(); // refresh }
Example 5
Source File: CombinedChartActivity.java From StockChart-MPAndroidChart with MIT License | 5 votes |
private BarData generateBarData() { ArrayList<BarEntry> entries1 = new ArrayList<>(); ArrayList<BarEntry> entries2 = new ArrayList<>(); for (int index = 0; index < count; index++) { entries1.add(new BarEntry(0, getRandom(25, 25))); // stacked entries2.add(new BarEntry(0, new float[]{getRandom(13, 12), getRandom(13, 12)})); } BarDataSet set1 = new BarDataSet(entries1, "Bar 1"); set1.setColor(Color.rgb(60, 220, 78)); set1.setValueTextColor(Color.rgb(60, 220, 78)); set1.setValueTextSize(10f); set1.setAxisDependency(YAxis.AxisDependency.LEFT); BarDataSet set2 = new BarDataSet(entries2, ""); set2.setStackLabels(new String[]{"Stack 1", "Stack 2"}); set2.setColors(Color.rgb(61, 165, 255), Color.rgb(23, 197, 255)); set2.setValueTextColor(Color.rgb(61, 165, 255)); set2.setValueTextSize(10f); set2.setAxisDependency(YAxis.AxisDependency.LEFT); float groupSpace = 0.06f; float barSpace = 0.02f; // x2 dataset float barWidth = 0.45f; // x2 dataset // (0.45 + 0.02) * 2 + 0.06 = 1.00 -> interval per "group" BarData d = new BarData(set1, set2); d.setBarWidth(barWidth); // make this BarData object grouped d.groupBars(0, groupSpace, barSpace); // start at x = 0 return d; }
Example 6
Source File: TestCaseRunner.java From SQLite-Performance with The Unlicense | 5 votes |
TestCaseRunner(int iterations, BarChart chart, String title, int color, IValueFormatter valueFormatter) { mIterations = iterations; mChart = chart; mEntries = new LinkedList<>(); mDataSet = new BarDataSet(mEntries, title); mDataSet.setValueFormatter(valueFormatter); mDataSet.setColor(color); }
Example 7
Source File: BarGraph.java From fastnfitness with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void draw(List<BarEntry> entries, ArrayList<String> xAxisLabel) { mChart.clear(); if (entries.isEmpty()) { return; } XAxis xAxis = this.mChart.getXAxis(); xAxis.setValueFormatter(new IndexAxisValueFormatter(xAxisLabel)); Collections.sort(entries, new EntryXComparator()); BarDataSet set1 = new BarDataSet(entries, mChartName); set1.setColor(mContext.getResources().getColor(R.color.toolbar_background)); // Create a data object with the datasets BarData data = new BarData(set1); data.setValueTextSize(12); data.setValueFormatter(new IValueFormatter() { private DecimalFormat mFormat = new DecimalFormat("#.## kg"); @Override public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { return mFormat.format(value); } }); // Set data mChart.setData(data); mChart.getAxisLeft().setAxisMinimum(0f); mChart.invalidate(); }
Example 8
Source File: AnalysisFragment.java From outlay with Apache License 2.0 | 5 votes |
@Override public void showAnalysis(Report report) { List<BarEntry> barEntries = new ArrayList<>(); List<Expense> expenses = report.getExpenses(); for (int i = 0; i < expenses.size(); i++) { Expense expense = expenses.get(i); barEntries.add(new BarEntry( i, expense.getAmount().floatValue()) ); } BarDataSet barSet = new BarDataSet(barEntries, ""); barSet.setColor(selectedCategory.getColor()); List<IBarDataSet> dataSets = new ArrayList<>(); dataSets.add(barSet); BarData data = new BarData(dataSets); data.setValueTextSize(10f); data.setValueTextColor(getOutlayTheme().secondaryTextColor); data.setBarWidth(0.9f); dayAxisValueFormatter.setExpenses(expenses); barChart.setData(data); barChart.invalidate(); barChart.animateY(500); }
Example 9
Source File: DailyBarChart.java From AndroidApp with GNU Affero General Public License v3.0 | 5 votes |
private BarData createDataSet() { ArrayList<BarEntry> entries = new ArrayList<>(); BarData chart2_bardata = new BarData(); BarDataSet chart2_dataset = new BarDataSet(entries, "kWh"); chart2_dataset.setColor(ContextCompat.getColor(context, R.color.colorAccent)); chart2_dataset.setValueTextColor(ContextCompat.getColor(context, R.color.lightGrey)); chart2_dataset.setValueTextSize(context.getResources().getInteger(R.integer.chartValueTextSize)); chart2_dataset.setValueFormatter(new Chart2ValueFormatter()); chart2_bardata.addDataSet(chart2_dataset); barChart.setData(chart2_bardata); return chart2_bardata; }
Example 10
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 11
Source File: CombinedChartActivity.java From Stayfit with Apache License 2.0 | 4 votes |
private BarData generateBarData() { BarData d = new BarData(); ArrayList<BarEntry> entries = new ArrayList<BarEntry>(); for (int index = 0; index < itemcount; index++) entries.add(new BarEntry(getRandom(15, 30), index)); BarDataSet set = new BarDataSet(entries, "Bar DataSet"); set.setColor(Color.rgb(60, 220, 78)); set.setValueTextColor(Color.rgb(60, 220, 78)); set.setValueTextSize(10f); d.addDataSet(set); set.setAxisDependency(YAxis.AxisDependency.LEFT); return d; }
Example 12
Source File: ChartActivity.java From Stayfit with Apache License 2.0 | 4 votes |
private ArrayList<BarDataSet> getDataSet() { ArrayList<BarDataSet> dataSets = null; ArrayList<BarEntry> valueSet1 = new ArrayList<>(); BarEntry v1e1 = new BarEntry(110.000f, 0); // Jan valueSet1.add(v1e1); BarEntry v1e2 = new BarEntry(40.000f, 1); // Feb valueSet1.add(v1e2); BarEntry v1e3 = new BarEntry(60.000f, 2); // Mar valueSet1.add(v1e3); BarEntry v1e4 = new BarEntry(30.000f, 3); // Apr valueSet1.add(v1e4); BarEntry v1e5 = new BarEntry(90.000f, 4); // May valueSet1.add(v1e5); BarEntry v1e6 = new BarEntry(100.000f, 5); // Jun valueSet1.add(v1e6); ArrayList<BarEntry> valueSet2 = new ArrayList<>(); BarEntry v2e1 = new BarEntry(150.000f, 0); // Jan valueSet2.add(v2e1); BarEntry v2e2 = new BarEntry(90.000f, 1); // Feb valueSet2.add(v2e2); BarEntry v2e3 = new BarEntry(120.000f, 2); // Mar valueSet2.add(v2e3); BarEntry v2e4 = new BarEntry(60.000f, 3); // Apr valueSet2.add(v2e4); BarEntry v2e5 = new BarEntry(20.000f, 4); // May valueSet2.add(v2e5); BarEntry v2e6 = new BarEntry(80.000f, 5); // Jun valueSet2.add(v2e6); BarDataSet barDataSet1 = new BarDataSet(valueSet1, "Brand 1"); barDataSet1.setColor(Color.rgb(0, 155, 0)); BarDataSet barDataSet2 = new BarDataSet(valueSet2, "Brand 2"); barDataSet2.setColors(ColorTemplate.COLORFUL_COLORS); dataSets = new ArrayList<>(); dataSets.add(barDataSet1); dataSets.add(barDataSet2); return dataSets; }
Example 13
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 14
Source File: ReportAdapter.java From privacy-friendly-interval-timer with GNU General Public License v3.0 | 4 votes |
@Override public void onBindViewHolder(ViewHolder holder, int position) { switch (getItemViewType(position)) { case TYPE_CHART: ActivityChart barChartData = (ActivityChart) mItems.get(position); CombinedChartViewHolder barChartViewHolder = (CombinedChartViewHolder) holder; barChartViewHolder.mTitleTextView.setText(barChartData.getTitle()); int barChartI = 0; ArrayList<String> barChartXValues = new ArrayList<>(); Map<String, Double> barChartDataMap; String barChartLabel; if (barChartData.getDisplayedDataType() == null) { barChartDataMap = barChartData.getTime(); barChartLabel = barChartViewHolder.context.getString(R.string.report_workout_time); } else { switch (barChartData.getDisplayedDataType()) { case CALORIES: barChartDataMap = barChartData.getCalories(); barChartLabel = barChartViewHolder.context.getString(R.string.report_calories); break; case TIME: default: barChartDataMap = barChartData.getTime(); barChartLabel = barChartViewHolder.context.getString(R.string.report_workout_time); break; } } List<BarEntry> dataEntries = new ArrayList<>(); for (Map.Entry<String, Double> dataEntry : barChartDataMap.entrySet()) { barChartXValues.add(barChartI, dataEntry.getKey()); if (dataEntry.getValue() != null) { float val = dataEntry.getValue().floatValue(); dataEntries.add(new BarEntry(barChartI, val)); } barChartI++; } BarDataSet barDataSet = new BarDataSet(dataEntries, barChartLabel); String formatPattern = "###,###,##0.0"; barDataSet.setValueFormatter(new DoubleValueFormatter(formatPattern)); ArrayList<ILineDataSet> lineDataSets = new ArrayList<>(); // make sure, that the first and last entry are fully displayed Entry start = new Entry(0, 0); Entry end = new Entry(barChartI - 1, 0); LineDataSet chartLineDataSet = new LineDataSet(Arrays.asList(start, end), ""); chartLineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT); chartLineDataSet.setDrawCircles(false); chartLineDataSet.setColor(ContextCompat.getColor(barChartViewHolder.context, R.color.transparent), 0); chartLineDataSet.setDrawValues(false); lineDataSets.add(chartLineDataSet); CombinedData combinedData = new CombinedData(); BarData barData = new BarData(barDataSet); barData.setBarWidth(0.5f); combinedData.setData(barData); combinedData.setData(new LineData(lineDataSets)); barDataSet.setColor(ContextCompat.getColor(barChartViewHolder.context, R.color.colorPrimary)); barChartViewHolder.mChart.setData(combinedData); barChartViewHolder.mChart.getXAxis().setValueFormatter(new ArrayListAxisValueFormatter(barChartXValues)); barChartViewHolder.mChart.invalidate(); break; case TYPE_SUMMARY: ActivitySummary summaryData = (ActivitySummary) mItems.get(position); SummaryViewHolder summaryViewHolder = (SummaryViewHolder) holder; summaryViewHolder.mTitleTextView.setText(summaryData.getTitle()); summaryViewHolder.mTimeTextView.setText(formatTime(summaryData.getTime())); summaryViewHolder.mCaloriesTextView.setText(String.valueOf(summaryData.getCalories())); break; } }
Example 15
Source File: ActivitiesChartActivity.java From Mi-Band with GNU General Public License v2.0 | 4 votes |
private void populateChart() { Calendar before = Calendar.getInstance(); before.add(Calendar.DAY_OF_WEEK, -7); Calendar today = Calendar.getInstance(); today.setTimeInMillis(System.currentTimeMillis()); //Log.i(TAG, "data from " + DateUtils.convertString(before) + " to " + DateUtils.convertString(today)); ArrayList<ActivityData> allActivities = ActivitySQLite.getInstance(ActivitiesChartActivity.this) .getActivitySamples(before.getTimeInMillis(), today.getTimeInMillis()); //.getAllActivities(); ArrayList<String> xVals = new ArrayList<String>(); ArrayList<BarEntry> unknown = new ArrayList<BarEntry>(); int i = 0; Calendar cal = Calendar.getInstance(); cal.clear(); Date date; String dateStringFrom = ""; String dateStringTo = ""; SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); SimpleDateFormat annotationDateFormat = new SimpleDateFormat("HH:mm"); float movementDivisor = 180.0f; float value; for (ActivityData ad : allActivities) { // determine start and end dates if (i == 0) { cal.setTimeInMillis(ad.getTimestamp() * 1000L); // make sure it's converted to long date = cal.getTime(); dateStringFrom = dateFormat.format(date); } else if (i == allActivities.size() - 1) { cal.setTimeInMillis(ad.getTimestamp() * 1000L); // same here date = cal.getTime(); dateStringTo = dateFormat.format(date); } String xLabel = ""; cal.setTimeInMillis(ad.getTimestamp() * 1000L); date = cal.getTime(); String dateString = annotationDateFormat.format(date); xLabel = dateString; xVals.add(xLabel); Log.i(TAG, "date " + dateString); Log.i(TAG, "steps " + ad.getSteps()); value = ((float) ad.getIntensity() / movementDivisor); unknown.add(new BarEntry(value, i)); i++; } //BarDataSet set1 = new BarDataSet(deep, "Deep Sleep"); //set1.setColor(Color.BLUE); //BarDataSet set2 = new BarDataSet(light, "Light Sleep"); //set2.setColor(Color.CYAN); BarDataSet set3 = new BarDataSet(unknown, "Activity"); set3.setColor(Color.RED); ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>(); //dataSets.add(set1); //dataSets.add(set2); dataSets.add(set3); BarData data = new BarData(xVals, dataSets); // data.setValueFormatter(new LargeValueFormatter()); // add space between the dataset groups in percent of bar-width data.setGroupSpace(0); mChart.setDescription(String.format("From %1$s to %2$s", dateStringFrom, dateStringTo)); mChart.setData(data); mChart.invalidate(); mChart.animateY(2000, Easing.EasingOption.EaseInOutQuart); }
Example 16
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(); }