com.github.mikephil.charting.interfaces.datasets.IDataSet Java Examples
The following examples show how to use
com.github.mikephil.charting.interfaces.datasets.IDataSet.
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: ChartData.java From Stayfit with Apache License 2.0 | 6 votes |
/** * Removes the given Entry object from the DataSet at the specified index. * * @param e * @param dataSetIndex */ public boolean removeEntry(Entry e, int dataSetIndex) { // entry null, outofbounds if (e == null || dataSetIndex >= mDataSets.size()) return false; IDataSet set = mDataSets.get(dataSetIndex); if (set != null) { // remove the entry from the dataset boolean removed = set.removeEntry(e); if (removed) { mYValCount -= 1; calcMinMax(0, mYValCount); } return removed; } else return false; }
Example #2
Source File: ScatterChartManager.java From react-native-mp-android-chart with MIT License | 6 votes |
@Override void dataSetConfig(IDataSet<Entry> dataSet, ReadableMap config) { ScatterDataSet scatterDataSet = (ScatterDataSet) dataSet; ChartDataSetConfigUtils.commonConfig(scatterDataSet, config); ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(scatterDataSet, config); ChartDataSetConfigUtils.commonLineScatterCandleRadarConfig(scatterDataSet, config); // ScatterDataSet only config if (BridgeUtils.validate(config, ReadableType.Number, "scatterShapeSize")) { scatterDataSet.setScatterShapeSize((float) config.getDouble("scatterShapeSize")); } if (BridgeUtils.validate(config, ReadableType.String, "scatterShape")) { scatterDataSet.setScatterShape(ScatterShape.valueOf(config.getString("scatterShape").toUpperCase())); } if (BridgeUtils.validate(config, ReadableType.String, "scatterShapeHoleColor")) { scatterDataSet.setScatterShapeHoleColor(Color.parseColor(config.getString("scatterShapeHoleColor"))); } if (BridgeUtils.validate(config, ReadableType.Number, "scatterShapeHoleRadius")) { scatterDataSet.setScatterShapeHoleRadius((float) config.getDouble("scatterShapeHoleRadius")); } }
Example #3
Source File: ChartData.java From android-kline with Apache License 2.0 | 6 votes |
/** * Removes the given Entry object from the DataSet at the specified index. * * @param e * @param dataSetIndex */ public boolean removeEntry(Entry e, int dataSetIndex) { // entry null, outofbounds if (e == null || dataSetIndex >= mDataSets.size()) return false; IDataSet set = mDataSets.get(dataSetIndex); if (set != null) { // remove the entry from the dataset boolean removed = set.removeEntry(e); if (removed) { calcMinMax(); } return removed; } else return false; }
Example #4
Source File: ChartData.java From android-kline with Apache License 2.0 | 6 votes |
/** * Adds an Entry to the DataSet at the specified index. * Entries are added to the end of the list. * * @param e * @param dataSetIndex */ public void addEntry(Entry e, int dataSetIndex) { if (mDataSets.size() > dataSetIndex && dataSetIndex >= 0) { IDataSet set = mDataSets.get(dataSetIndex); // add the entry to the dataset if (!set.addEntry(e)) return; calcMinMax(e, set.getAxisDependency()); } else { Log.e("addEntry", "Cannot add Entry because dataSetIndex too high or too low."); } }
Example #5
Source File: Chart.java From Ticket-Analysis with MIT License | 6 votes |
/** * Sets a new data object for the chart. The data object contains all values * and information needed for displaying. * * @param data */ public void setData(T data) { mData = data; mOffsetsCalculated = false; if (data == null) { return; } // calculate how many digits are needed setupDefaultFormatter(data.getYMin(), data.getYMax()); for (IDataSet set : mData.getDataSets()) { if (set.needsFormatter() || set.getValueFormatter() == mDefaultValueFormatter) set.setValueFormatter(mDefaultValueFormatter); } // let the chart know there is new data notifyDataSetChanged(); if (mLogEnabled) Log.i(LOG_TAG, "Data is set."); }
Example #6
Source File: ChartData.java From StockChart-MPAndroidChart with MIT License | 6 votes |
/** * Removes the given Entry object from the DataSet at the specified index. * * @param e * @param dataSetIndex */ public boolean removeEntry(Entry e, int dataSetIndex) { // entry null, outofbounds if (e == null || dataSetIndex >= mDataSets.size()) { return false; } IDataSet set = mDataSets.get(dataSetIndex); if (set != null) { // remove the entry from the dataset boolean removed = set.removeEntry(e); if (removed) { calcMinMax(); } return removed; } else { return false; } }
Example #7
Source File: ChartData.java From StockChart-MPAndroidChart with MIT License | 6 votes |
/** * Adds an Entry to the DataSet at the specified index. * Entries are added to the end of the list. * * @param e * @param dataSetIndex */ public void addEntry(Entry e, int dataSetIndex) { if (mDataSets.size() > dataSetIndex && dataSetIndex >= 0) { IDataSet set = mDataSets.get(dataSetIndex); // add the entry to the dataset if (!set.addEntry(e)) { return; } calcMinMax(e, set.getAxisDependency()); } else { Log.e("addEntry", "Cannot add Entry because dataSetIndex too high or too low."); } }
Example #8
Source File: ChartData.java From NetKnight with Apache License 2.0 | 6 votes |
/** * Removes the given Entry object from the DataSet at the specified index. * * @param e * @param dataSetIndex */ public boolean removeEntry(Entry e, int dataSetIndex) { // entry null, outofbounds if (e == null || dataSetIndex >= mDataSets.size()) return false; IDataSet set = mDataSets.get(dataSetIndex); if (set != null) { // remove the entry from the dataset boolean removed = set.removeEntry(e); if (removed) { mYValCount -= 1; calcMinMax(0, mYValCount); } return removed; } else return false; }
Example #9
Source File: ChartData.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * Sets a custom IValueFormatter for all DataSets this data object contains. * * @param f */ public void setValueFormatter(ValueFormatter f) { if (f == null) { return; } else { for (IDataSet set : mDataSets) { set.setValueFormatter(f); } } }
Example #10
Source File: CandleStickChartManager.java From react-native-mp-android-chart with MIT License | 5 votes |
@Override void dataSetConfig(IDataSet<CandleEntry> dataSet, ReadableMap config) { CandleDataSet candleDataSet = (CandleDataSet) dataSet; ChartDataSetConfigUtils.commonConfig(candleDataSet, config); ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(candleDataSet, config); ChartDataSetConfigUtils.commonLineScatterCandleRadarConfig(candleDataSet, config); // CandleDataSet only config if (BridgeUtils.validate(config, ReadableType.Number, "barSpace")) { candleDataSet.setBarSpace((float) config.getDouble("barSpace")); } if (BridgeUtils.validate(config, ReadableType.Number, "shadowWidth")) { candleDataSet.setShadowWidth((float) config.getDouble("shadowWidth")); } if (BridgeUtils.validate(config, ReadableType.String, "shadowColor")) { candleDataSet.setShadowColor(Color.parseColor(config.getString("shadowColor"))); } if (BridgeUtils.validate(config, ReadableType.Boolean, "shadowColorSameAsCandle")) { candleDataSet.setShadowColorSameAsCandle(config.getBoolean("shadowColorSameAsCandle")); } if (BridgeUtils.validate(config, ReadableType.String, "neutralColor")) { candleDataSet.setNeutralColor(Color.parseColor(config.getString("neutralColor"))); } if (BridgeUtils.validate(config, ReadableType.String, "decreasingColor")) { candleDataSet.setDecreasingColor(Color.parseColor(config.getString("decreasingColor"))); } if (BridgeUtils.validate(config, ReadableType.String, "decreasingPaintStyle")) { candleDataSet.setDecreasingPaintStyle(Paint.Style.valueOf(config.getString("decreasingPaintStyle").toUpperCase())); } if (BridgeUtils.validate(config, ReadableType.String, "increasingColor")) { candleDataSet.setIncreasingColor(Color.parseColor(config.getString("increasingColor"))); } if (BridgeUtils.validate(config, ReadableType.String, "increasingPaintStyle")) { candleDataSet.setIncreasingPaintStyle(Paint.Style.valueOf(config.getString("increasingPaintStyle").toUpperCase())); } }
Example #11
Source File: ChartData.java From NetKnight with Apache License 2.0 | 5 votes |
/** * Sets a custom ValueFormatter for all DataSets this data object contains. * * @param f */ public void setValueFormatter(ValueFormatter f) { if (f == null) return; else { for (IDataSet set : mDataSets) { set.setValueFormatter(f); } } }
Example #12
Source File: ChartBaseManager.java From react-native-mp-android-chart with MIT License | 5 votes |
/** * * Dataset config details: https://github.com/PhilJay/MPAndroidChart/wiki/DataSet-classes-in-detail */ @ReactProp(name = "data") public void setData(Chart chart, ReadableMap propMap) { if (!BridgeUtils.validate(propMap, ReadableType.Array, "datasets")) { return; } String[] xValues = new String[0]; if (BridgeUtils.validate(propMap, ReadableType.Array, "xValues")) { xValues = BridgeUtils.convertToStringArray(propMap.getArray("xValues")); } ChartData<IDataSet<U>> chartData = createData(xValues); ReadableArray datasets = propMap.getArray("datasets"); for (int i = 0; i < datasets.size(); i++) { ReadableMap dataset = datasets.getMap(i); // TODO validation ReadableArray yValues = dataset.getArray("yValues"); String label = dataset.getString("label"); ArrayList<U> entries = createEntries(yValues); IDataSet<U> lineDataSet = createDataSet(entries, label); if (BridgeUtils.validate(dataset, ReadableType.Map, "config")) { dataSetConfig(lineDataSet, dataset.getMap("config")); } chartData.addDataSet(lineDataSet); } chart.setData(chartData); chart.invalidate(); }
Example #13
Source File: ChartData.java From Stayfit with Apache License 2.0 | 5 votes |
/** * Removes the Entry object at the given xIndex from the DataSet at the * specified index. Returns true if an Entry was removed, false if no Entry * was found that meets the specified requirements. * * @param xIndex * @param dataSetIndex * @return */ public boolean removeEntry(int xIndex, int dataSetIndex) { if (dataSetIndex >= mDataSets.size()) return false; IDataSet dataSet = mDataSets.get(dataSetIndex); Entry e = dataSet.getEntryForXIndex(xIndex); if (e == null || e.getXIndex() != xIndex) return false; return removeEntry(e, dataSetIndex); }
Example #14
Source File: ChartData.java From android-kline with Apache License 2.0 | 5 votes |
/** * Returns true if highlighting of all underlying values is enabled, false * if not. * * @return */ public boolean isHighlightEnabled() { for (IDataSet set : mDataSets) { if (!set.isHighlightEnabled()) return false; } return true; }
Example #15
Source File: Chart.java From Stayfit with Apache License 2.0 | 5 votes |
/** * Sets a new data object for the chart. The data object contains all values * and information needed for displaying. * * @param data */ public void setData(T data) { if (data == null) { Log.e(LOG_TAG, "Cannot set data for chart. Provided data object is null."); return; } // LET THE CHART KNOW THERE IS DATA mOffsetsCalculated = false; mData = data; // calculate how many digits are needed calculateFormatter(data.getYMin(), data.getYMax()); for (IDataSet set : mData.getDataSets()) { if (Utils.needsDefaultFormatter(set.getValueFormatter())) set.setValueFormatter(mDefaultFormatter); } // let the chart know there is new data notifyDataSetChanged(); if (mLogEnabled) Log.i(LOG_TAG, "Data is set."); }
Example #16
Source File: GraphsActivity.java From your-local-weather with GNU General Public License v3.0 | 5 votes |
private void toggleValuesForGraph(LineData lineData) { if (lineData == null) { return; } for (IDataSet set : lineData.getDataSets()) { set.setDrawValues(!set.isDrawValuesEnabled()); } }
Example #17
Source File: ChartData.java From NetKnight with Apache License 2.0 | 5 votes |
/** * Removes the Entry object at the given xIndex from the DataSet at the * specified index. Returns true if an Entry was removed, false if no Entry * was found that meets the specified requirements. * * @param xIndex * @param dataSetIndex * @return */ public boolean removeEntry(int xIndex, int dataSetIndex) { if (dataSetIndex >= mDataSets.size()) return false; IDataSet dataSet = mDataSets.get(dataSetIndex); Entry e = dataSet.getEntryForXIndex(xIndex); if (e == null || e.getXIndex() != xIndex) return false; return removeEntry(e, dataSetIndex); }
Example #18
Source File: CombinedChartKline.java From shinny-futures-android with GNU General Public License v3.0 | 5 votes |
@Override protected void drawMarkers(Canvas canvas) { // if there is no marker view or drawing marker is disabled if (mMarker == null || !isDrawMarkersEnabled() || !valuesToHighlight()) return; for (Highlight highlight : mIndicesToHighlight) { IDataSet set = mData.getDataSetByIndex(highlight.getDataSetIndex()); Entry e = getEntryForHighlight(highlight); int entryIndex = set.getEntryIndex(e); // make sure entry not null if (e == null || entryIndex > set.getEntryCount() * mAnimator.getPhaseX()) continue; float[] pos = getMarkerPosition(highlight); // check bounds // if (!mViewPortHandler.isInBounds(pos[0], pos[1])) // continue; // callbacks to initQuotes the content mMarker.refreshContent(e, highlight); // draw the marker mMarker.draw(canvas, pos[0], pos[1]); } }
Example #19
Source File: ChartData.java From android-kline with Apache License 2.0 | 5 votes |
/** * Sets a custom IValueFormatter for all DataSets this data object contains. * * @param f */ public void setValueFormatter(IValueFormatter f) { if (f == null) return; else { for (IDataSet set : mDataSets) { set.setValueFormatter(f); } } }
Example #20
Source File: Chart.java From android-kline with Apache License 2.0 | 5 votes |
/** * draws all MarkerViews on the highlighted positions */ protected void drawMarkers(Canvas canvas) { // if there is no marker view or drawing marker is disabled if (mMarker == null || !isDrawMarkersEnabled() || !valuesToHighlight()) return; for (int i = 0; i < mIndicesToHighlight.length; i++) { Highlight highlight = mIndicesToHighlight[i]; IDataSet set = mData.getDataSetByIndex(highlight.getDataSetIndex()); Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]); int entryIndex = set.getEntryIndex(e); // make sure entry not null if (e == null || entryIndex > set.getEntryCount() * mAnimator.getPhaseX()) continue; float[] pos = getMarkerPosition(highlight); // check bounds if (!mViewPortHandler.isInBounds(pos[0], pos[1])) continue; // callbacks to update the content mMarker.refreshContent(e, highlight); // draw the marker mMarker.draw(canvas, pos[0], pos[1]); } }
Example #21
Source File: ChartData.java From NetKnight with Apache License 2.0 | 5 votes |
/** * Returns true if highlighting of all underlying values is enabled, false * if not. * * @return */ public boolean isHighlightEnabled() { for (IDataSet set : mDataSets) { if (!set.isHighlightEnabled()) return false; } return true; }
Example #22
Source File: HorizontalBarHighlighter.java From Ticket-Analysis with MIT License | 5 votes |
@Override protected List<Highlight> buildHighlights(IDataSet set, int dataSetIndex, float xVal, DataSet.Rounding rounding) { ArrayList<Highlight> highlights = new ArrayList<>(); //noinspection unchecked List<Entry> entries = set.getEntriesForXValue(xVal); if (entries.size() == 0) { // Try to find closest x-value and take all entries for that x-value final Entry closest = set.getEntryForXValue(xVal, Float.NaN, rounding); if (closest != null) { //noinspection unchecked entries = set.getEntriesForXValue(closest.getX()); } } if (entries.size() == 0) return highlights; for (Entry e : entries) { MPPointD pixels = mChart.getTransformer( set.getAxisDependency()).getPixelForValues(e.getY(), e.getX()); highlights.add(new Highlight( e.getX(), e.getY(), (float) pixels.x, (float) pixels.y, dataSetIndex, set.getAxisDependency())); } return highlights; }
Example #23
Source File: ChartHighlighter.java From Ticket-Analysis with MIT License | 5 votes |
/** * An array of `Highlight` objects corresponding to the selected xValue and dataSetIndex. * * @param set * @param dataSetIndex * @param xVal * @param rounding * @return */ protected List<Highlight> buildHighlights(IDataSet set, int dataSetIndex, float xVal, DataSet.Rounding rounding) { ArrayList<Highlight> highlights = new ArrayList<>(); //noinspection unchecked List<Entry> entries = set.getEntriesForXValue(xVal); if (entries.size() == 0) { // Try to find closest x-value and take all entries for that x-value final Entry closest = set.getEntryForXValue(xVal, Float.NaN, rounding); if (closest != null) { //noinspection unchecked entries = set.getEntriesForXValue(closest.getX()); } } if (entries.size() == 0) return highlights; for (Entry e : entries) { MPPointD pixels = mChart.getTransformer( set.getAxisDependency()).getPixelForValues(e.getX(), e.getY()); highlights.add(new Highlight( e.getX(), e.getY(), (float) pixels.x, (float) pixels.y, dataSetIndex, set.getAxisDependency())); } return highlights; }
Example #24
Source File: ChartData.java From Ticket-Analysis with MIT License | 5 votes |
/** * Returns true if highlighting of all underlying values is enabled, false * if not. * * @return */ public boolean isHighlightEnabled() { for (IDataSet set : mDataSets) { if (!set.isHighlightEnabled()) return false; } return true; }
Example #25
Source File: ChartData.java From Ticket-Analysis with MIT License | 5 votes |
/** * Removes the Entry object closest to the given DataSet at the * specified index. Returns true if an Entry was removed, false if no Entry * was found that meets the specified requirements. * * @param xValue * @param dataSetIndex * @return */ public boolean removeEntry(float xValue, int dataSetIndex) { if (dataSetIndex >= mDataSets.size()) return false; IDataSet dataSet = mDataSets.get(dataSetIndex); Entry e = dataSet.getEntryForXValue(xValue, Float.NaN); if (e == null) return false; return removeEntry(e, dataSetIndex); }
Example #26
Source File: ChartData.java From Ticket-Analysis with MIT License | 5 votes |
/** * Sets a custom IValueFormatter for all DataSets this data object contains. * * @param f */ public void setValueFormatter(IValueFormatter f) { if (f == null) return; else { for (IDataSet set : mDataSets) { set.setValueFormatter(f); } } }
Example #27
Source File: CombinedChartCurrentDay.java From shinny-futures-android with GNU General Public License v3.0 | 5 votes |
@Override protected void drawMarkers(Canvas canvas) { // if there is no marker view or drawing marker is disabled if (mMarker == null || !isDrawMarkersEnabled() || !valuesToHighlight()) return; for (Highlight highlight : mIndicesToHighlight) { IDataSet set = mData.getDataSetByIndex(highlight.getDataSetIndex()); Entry e = getEntryForHighlight(highlight); int entryIndex = set.getEntryIndex(e); // make sure entry not null if (e == null || entryIndex > set.getEntryCount() * mAnimator.getPhaseX()) continue; float[] pos = getMarkerPosition(highlight); //注释掉,在三图范围内,保持marker始终出现 // check bounds // if (!mViewPortHandler.isInBoundsX(pos[0])) // continue; // callbacks to initQuotes the content mMarker.refreshContent(e, highlight); // draw the marker mMarker.draw(canvas, pos[0], pos[1]); } }
Example #28
Source File: BarChartActivity.java From Stayfit with Apache License 2.0 | 4 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.actionToggleValues: { for (IDataSet set : mChart.getData().getDataSets()) set.setDrawValues(!set.isDrawValuesEnabled()); mChart.invalidate(); break; } case R.id.actionToggleHighlight: { if(mChart.getData() != null) { mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled()); mChart.invalidate(); } break; } case R.id.actionTogglePinch: { if (mChart.isPinchZoomEnabled()) mChart.setPinchZoom(false); else mChart.setPinchZoom(true); mChart.invalidate(); break; } case R.id.actionToggleAutoScaleMinMax: { mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled()); mChart.notifyDataSetChanged(); break; } case R.id.actionToggleHighlightArrow: { if (mChart.isDrawHighlightArrowEnabled()) mChart.setDrawHighlightArrow(false); else mChart.setDrawHighlightArrow(true); mChart.invalidate(); break; } case R.id.animateX: { mChart.animateX(3000); break; } case R.id.animateY: { mChart.animateY(3000); break; } case R.id.animateXY: { mChart.animateXY(3000, 3000); break; } case R.id.actionSave: { if (mChart.saveToGallery("title" + System.currentTimeMillis(), 50)) { Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!", Toast.LENGTH_SHORT).show(); } else Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT) .show(); break; } } return true; }
Example #29
Source File: ChartData.java From Ticket-Analysis with MIT License | 4 votes |
/** * Enables / disables highlighting values for all DataSets this data object * contains. If set to true, this means that values can * be highlighted programmatically or by touch gesture. */ public void setHighlightEnabled(boolean enabled) { for (IDataSet set : mDataSets) { set.setHighlightEnabled(enabled); } }
Example #30
Source File: ChartHighlighter.java From android-kline with Apache License 2.0 | 4 votes |
/** * Returns a list of Highlight objects representing the entries closest to the given xVal. * The returned list contains two objects per DataSet (closest rounding up, closest rounding down). * * @param xVal the transformed x-value of the x-touch position * @param x touch position * @param y touch position * @return */ protected List<Highlight> getHighlightsAtXValue(float xVal, float x, float y) { mHighlightBuffer.clear(); BarLineScatterCandleBubbleData data = getData(); if (data == null) return mHighlightBuffer; for (int i = 0, dataSetCount = data.getDataSetCount(); i < dataSetCount; i++) { IDataSet dataSet = data.getDataSetByIndex(i); // don't include DataSets that cannot be highlighted if (!dataSet.isHighlightEnabled()) continue; mHighlightBuffer.addAll(buildHighlights(dataSet, i, xVal, DataSet.Rounding.CLOSEST)); } return mHighlightBuffer; }