Java Code Examples for com.github.mikephil.charting.data.DataSet#getEntryCount()
The following examples show how to use
com.github.mikephil.charting.data.DataSet#getEntryCount() .
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: BarChart.java From Notification-Analyser with MIT License | 6 votes |
@Override protected void calcMinMax(boolean fixedValues) { super.calcMinMax(fixedValues); // increase deltax by 1 because the bars have a width of 1 mDeltaX++; // extend xDelta to make space for multiple datasets (if ther are one) mDeltaX *= mOriginalData.getDataSetCount(); int maxEntry = 0; for (int i = 0; i < mOriginalData.getDataSetCount(); i++) { DataSet<? extends Entry> set = mOriginalData.getDataSetByIndex(i); if (maxEntry < set.getEntryCount()) maxEntry = set.getEntryCount(); } float groupSpace = mOriginalData.getGroupSpace(); mDeltaX += maxEntry * groupSpace; }
Example 2
Source File: Chart.java From Notification-Analyser with MIT License | 5 votes |
/** * returns the average value for a specific DataSet (with a specific label) * in the chart * * @param dataSetLabel * @return */ public float getAverage(String dataSetLabel) { DataSet<? extends Entry> ds = mCurrentData.getDataSetByLabel(dataSetLabel, true); return ds.getYValueSum() / ds.getEntryCount(); }
Example 3
Source File: LegendRenderer.java From iMoney with Apache License 2.0 | 4 votes |
/** * Prepares the legend and calculates all needed forms, labels and colors. * * @param data */ public void computeLegend(ChartData<?> data) { if (!mLegend.isLegendCustom()) { List<String> labels = new ArrayList<String>(); List<Integer> colors = new ArrayList<Integer>(); // loop for building up the colors and labels used in the legend for (int i = 0; i < data.getDataSetCount(); i++) { DataSet<? extends Entry> dataSet = data.getDataSetByIndex(i); List<Integer> clrs = dataSet.getColors(); int entryCount = dataSet.getEntryCount(); // if we have a barchart with stacked bars if (dataSet instanceof BarDataSet && ((BarDataSet) dataSet).isStacked()) { BarDataSet bds = (BarDataSet) dataSet; String[] sLabels = bds.getStackLabels(); for (int j = 0; j < clrs.size() && j < bds.getStackSize(); j++) { labels.add(sLabels[j % sLabels.length]); colors.add(clrs.get(j)); } if (bds.getLabel() != null) { // add the legend description label colors.add(ColorTemplate.COLOR_SKIP); labels.add(bds.getLabel()); } } else if (dataSet instanceof PieDataSet) { List<String> xVals = data.getXVals(); PieDataSet pds = (PieDataSet) dataSet; for (int j = 0; j < clrs.size() && j < entryCount && j < xVals.size(); j++) { labels.add(xVals.get(j)); colors.add(clrs.get(j)); } if (pds.getLabel() != null) { // add the legend description label colors.add(ColorTemplate.COLOR_SKIP); labels.add(pds.getLabel()); } } else { // all others for (int j = 0; j < clrs.size() && j < entryCount; j++) { // if multiple colors are set for a DataSet, group them if (j < clrs.size() - 1 && j < entryCount - 1) { labels.add(null); } else { // add label to the last entry String label = data.getDataSetByIndex(i).getLabel(); labels.add(label); } colors.add(clrs.get(j)); } } } if (mLegend.getExtraColors() != null && mLegend.getExtraLabels() != null) { for (int color : mLegend.getExtraColors()) colors.add(color); Collections.addAll(labels, mLegend.getExtraLabels()); } mLegend.setComputedColors(colors); mLegend.setComputedLabels(labels); } Typeface tf = mLegend.getTypeface(); if (tf != null) mLegendLabelPaint.setTypeface(tf); mLegendLabelPaint.setTextSize(mLegend.getTextSize()); mLegendLabelPaint.setColor(mLegend.getTextColor()); // calculate all dimensions of the mLegend mLegend.calculateDimensions(mLegendLabelPaint, mViewPortHandler); }
Example 4
Source File: Chart.java From Notification-Analyser with MIT License | 4 votes |
/** * Generates an automatically prepared legend depending on the DataSets in * the chart and their colors. */ public void prepareLegend() { ArrayList<String> labels = new ArrayList<String>(); ArrayList<Integer> colors = new ArrayList<Integer>(); // loop for building up the colors and labels used in the legend for (int i = 0; i < mOriginalData.getDataSetCount(); i++) { DataSet<? extends Entry> dataSet = mOriginalData.getDataSetByIndex(i); ArrayList<Integer> clrs = dataSet.getColors(); int entryCount = dataSet.getEntryCount(); // if we have a barchart with stacked bars if (dataSet instanceof BarDataSet && ((BarDataSet) dataSet).getStackSize() > 1) { BarDataSet bds = (BarDataSet) dataSet; String[] sLabels = bds.getStackLabels(); for (int j = 0; j < clrs.size() && j < entryCount && j < bds.getStackSize(); j++) { labels.add(sLabels[j % sLabels.length]); colors.add(clrs.get(j)); } // add the legend description label colors.add(-2); labels.add(bds.getLabel()); } else if (dataSet instanceof PieDataSet) { ArrayList<String> xVals = mOriginalData.getXVals(); PieDataSet pds = (PieDataSet) dataSet; for (int j = 0; j < clrs.size() && j < entryCount && j < xVals.size(); j++) { labels.add(xVals.get(j)); colors.add(clrs.get(j)); } // add the legend description label colors.add(-2); labels.add(pds.getLabel()); } else { // all others for (int j = 0; j < clrs.size() && j < entryCount; j++) { // if multiple colors are set for a DataSet, group them if (j < clrs.size() - 1 && j < entryCount - 1) { labels.add(null); } else { // add label to the last entry String label = mOriginalData.getDataSetByIndex(i).getLabel(); labels.add(label); } colors.add(clrs.get(j)); } } } Legend l = new Legend(colors, labels); if (mLegend != null) { // apply the old legend settings to a potential new legend l.apply(mLegend); } mLegend = l; }