com.github.mikephil.charting.data.ChartData Java Examples
The following examples show how to use
com.github.mikephil.charting.data.ChartData.
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: CombinedChartCurrentDay.java From shinny-futures-android with GNU General Public License v3.0 | 6 votes |
/** * Get the Entry for a corresponding highlight object * * @param highlight * @return the entry that is highlighted */ public Entry getEntryForHighlight(Highlight highlight) { List<BarLineScatterCandleBubbleData> dataObjects = mData.getAllData(); if (highlight.getDataIndex() >= dataObjects.size()) return null; ChartData data = dataObjects.get(highlight.getDataIndex()); if (highlight.getDataSetIndex() >= data.getDataSetCount()) return null; else { // The value of the highlighted entry could be NaN - // if we are not interested in highlighting a specific value. List<Entry> entries = data.getDataSetByIndex(highlight.getDataSetIndex()) .getEntriesForXValue(highlight.getX()); return entries.get(0); } }
Example #2
Source File: SimpleFragment.java From Stayfit with Apache License 2.0 | 6 votes |
protected ScatterData generateScatterData(int dataSets, float range, int count) { ArrayList<IScatterDataSet> sets = new ArrayList<IScatterDataSet>(); ScatterShape[] shapes = ScatterChart.getAllPossibleShapes(); for(int i = 0; i < dataSets; i++) { ArrayList<Entry> entries = new ArrayList<Entry>(); for(int j = 0; j < count; j++) { entries.add(new Entry((float) (Math.random() * range) + range / 4, j)); } ScatterDataSet ds = new ScatterDataSet(entries, getLabel(i)); ds.setScatterShapeSize(12f); ds.setScatterShape(shapes[i % shapes.length]); ds.setColors(ColorTemplate.COLORFUL_COLORS); ds.setScatterShapeSize(9f); sets.add(ds); } ScatterData d = new ScatterData(ChartData.generateXVals(0, count), sets); d.setValueTypeface(tf); return d; }
Example #3
Source File: SimpleFragment.java From Stayfit with Apache License 2.0 | 6 votes |
protected BarData generateBarData(int dataSets, float range, int count) { ArrayList<IBarDataSet> sets = new ArrayList<IBarDataSet>(); for(int i = 0; i < dataSets; i++) { ArrayList<BarEntry> entries = new ArrayList<BarEntry>(); // entries = FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "stacked_bars.txt"); for(int j = 0; j < count; j++) { entries.add(new BarEntry((float) (Math.random() * range) + range / 4, j)); } BarDataSet ds = new BarDataSet(entries, getLabel(i)); ds.setColors(ColorTemplate.VORDIPLOM_COLORS); sets.add(ds); } BarData d = new BarData(ChartData.generateXVals(0, count), sets); d.setValueTypeface(tf); return d; }
Example #4
Source File: CombinedChartKline.java From shinny-futures-android with GNU General Public License v3.0 | 6 votes |
/** * Get the Entry for a corresponding highlight object * * @param highlight * @return the entry that is highlighted */ public Entry getEntryForHighlight(Highlight highlight) { List<BarLineScatterCandleBubbleData> dataObjects = mData.getAllData(); if (highlight.getDataIndex() >= dataObjects.size()) return null; ChartData data = dataObjects.get(highlight.getDataIndex()); if (highlight.getDataSetIndex() >= data.getDataSetCount()) return null; else { // The value of the highlighted entry could be NaN - // if we are not interested in highlighting a specific value. List<Entry> entries = data.getDataSetByIndex(highlight.getDataSetIndex()) .getEntriesForXValue(highlight.getX()); return entries.get(0); } }
Example #5
Source File: CombinedChartRenderer.java From android-kline with Apache License 2.0 | 5 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { Chart chart = mChart.get(); if (chart == null) return; for (DataRenderer renderer : mRenderers) { ChartData data = null; if (renderer instanceof BarChartRenderer) data = ((BarChartRenderer)renderer).mChart.getBarData(); else if (renderer instanceof LineChartRenderer) data = ((LineChartRenderer)renderer).mChart.getLineData(); else if (renderer instanceof CandleStickChartRenderer) data = ((CandleStickChartRenderer)renderer).mChart.getCandleData(); else if (renderer instanceof ScatterChartRenderer) data = ((ScatterChartRenderer)renderer).mChart.getScatterData(); else if (renderer instanceof BubbleChartRenderer) data = ((BubbleChartRenderer)renderer).mChart.getBubbleData(); int dataIndex = data == null ? -1 : ((CombinedData)chart.getData()).getAllData().indexOf(data); mHighlightBuffer.clear(); for (Highlight h : indices) { if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1) mHighlightBuffer.add(h); } renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()])); } }
Example #6
Source File: SimpleFragment.java From Stayfit with Apache License 2.0 | 5 votes |
protected LineData getComplexity() { ArrayList<ILineDataSet> sets = new ArrayList<ILineDataSet>(); LineDataSet ds1 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "n.txt"), "O(n)"); LineDataSet ds2 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "nlogn.txt"), "O(nlogn)"); LineDataSet ds3 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "square.txt"), "O(n\u00B2)"); LineDataSet ds4 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "three.txt"), "O(n\u00B3)"); ds1.setColor(ColorTemplate.VORDIPLOM_COLORS[0]); ds2.setColor(ColorTemplate.VORDIPLOM_COLORS[1]); ds3.setColor(ColorTemplate.VORDIPLOM_COLORS[2]); ds4.setColor(ColorTemplate.VORDIPLOM_COLORS[3]); ds1.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[0]); ds2.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[1]); ds3.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[2]); ds4.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[3]); ds1.setLineWidth(2.5f); ds1.setCircleRadius(3f); ds2.setLineWidth(2.5f); ds2.setCircleRadius(3f); ds3.setLineWidth(2.5f); ds3.setCircleRadius(3f); ds4.setLineWidth(2.5f); ds4.setCircleRadius(3f); // load DataSets from textfiles in assets folders sets.add(ds1); sets.add(ds2); sets.add(ds3); sets.add(ds4); LineData d = new LineData(ChartData.generateXVals(0, ds1.getEntryCount()), sets); d.setValueTypeface(tf); return d; }
Example #7
Source File: SimpleFragment.java From Stayfit with Apache License 2.0 | 5 votes |
protected LineData generateLineData() { // DataSet ds1 = new DataSet(n, "O(n)"); // DataSet ds2 = new DataSet(nlogn, "O(nlogn)"); // DataSet ds3 = new DataSet(nsquare, "O(n\u00B2)"); // DataSet ds4 = new DataSet(nthree, "O(n\u00B3)"); ArrayList<ILineDataSet> sets = new ArrayList<ILineDataSet>(); LineDataSet ds1 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "sine.txt"), "Sine function"); LineDataSet ds2 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "cosine.txt"), "Cosine function"); ds1.setLineWidth(2f); ds2.setLineWidth(2f); ds1.setDrawCircles(false); ds2.setDrawCircles(false); ds1.setColor(ColorTemplate.VORDIPLOM_COLORS[0]); ds2.setColor(ColorTemplate.VORDIPLOM_COLORS[1]); // load DataSets from textfiles in assets folders sets.add(ds1); sets.add(ds2); // sets.add(FileUtils.dataSetFromAssets(getActivity().getAssets(), "n.txt")); // sets.add(FileUtils.dataSetFromAssets(getActivity().getAssets(), "nlogn.txt")); // sets.add(FileUtils.dataSetFromAssets(getActivity().getAssets(), "square.txt")); // sets.add(FileUtils.dataSetFromAssets(getActivity().getAssets(), "three.txt")); int max = Math.max(sets.get(0).getEntryCount(), sets.get(1).getEntryCount()); LineData d = new LineData(ChartData.generateXVals(0, max), sets); d.setValueTypeface(tf); return d; }
Example #8
Source File: CombinedChartRenderer.java From NetKnight with Apache License 2.0 | 5 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { Chart chart = mChart.get(); if (chart == null) return; for (DataRenderer renderer : mRenderers) { ChartData data = null; if (renderer instanceof BarChartRenderer) data = ((BarChartRenderer)renderer).mChart.getBarData(); else if (renderer instanceof LineChartRenderer) data = ((LineChartRenderer)renderer).mChart.getLineData(); else if (renderer instanceof CandleStickChartRenderer) data = ((CandleStickChartRenderer)renderer).mChart.getCandleData(); else if (renderer instanceof ScatterChartRenderer) data = ((ScatterChartRenderer)renderer).mChart.getScatterData(); else if (renderer instanceof BubbleChartRenderer) data = ((BubbleChartRenderer)renderer).mChart.getBubbleData(); int dataIndex = data == null ? -1 : ((CombinedData)chart.getData()).getAllData().indexOf(data); ArrayList<Highlight> dataIndices = new ArrayList<>(); for (Highlight h : indices) { if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1) dataIndices.add(h); } renderer.drawHighlighted(c, dataIndices.toArray(new Highlight[dataIndices.size()])); } }
Example #9
Source File: CombinedHighlighter.java From NetKnight with Apache License 2.0 | 5 votes |
/** * Returns a list of SelectionDetail object corresponding to the given xIndex. * * @param xIndex * @return */ @Override protected List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex, int dataSetIndex) { List<SelectionDetail> vals = new ArrayList<SelectionDetail>(); float[] pts = new float[2]; CombinedData data = (CombinedData) mChart.getData(); // get all chartdata objects List<ChartData> dataObjects = data.getAllData(); for (int i = 0; i < dataObjects.size(); i++) { for(int j = 0; j < dataObjects.get(i).getDataSetCount(); j++) { IDataSet dataSet = dataObjects.get(i).getDataSetByIndex(j); // dont include datasets that cannot be highlighted if (!dataSet.isHighlightEnabled()) continue; // extract all y-values from all DataSets at the given x-index final float yVals[] = dataSet.getYValsForXIndex(xIndex); for (float yVal : yVals) { pts[1] = yVal; mChart.getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts); if (!Float.isNaN(pts[1])) { vals.add(new SelectionDetail(pts[1], yVal, i, j, dataSet)); } } } } return vals; }
Example #10
Source File: AppCombinedChartRenderer.java From android-kline with Apache License 2.0 | 5 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { Chart chart = mChart.get(); if (chart == null) return; for (DataRenderer renderer : mRenderers) { ChartData data = null; if (renderer instanceof BarChartRenderer) data = ((BarChartRenderer)renderer).mChart.getBarData(); else if (renderer instanceof AppLineChartRenderer) data = ((AppLineChartRenderer)renderer).mChart.getLineData(); else if (renderer instanceof CandleStickChartRenderer) data = ((CandleStickChartRenderer)renderer).mChart.getCandleData(); else if (renderer instanceof ScatterChartRenderer) data = ((ScatterChartRenderer)renderer).mChart.getScatterData(); else if (renderer instanceof BubbleChartRenderer) data = ((BubbleChartRenderer)renderer).mChart.getBubbleData(); int dataIndex = data == null ? -1 : ((CombinedData)chart.getData()).getAllData().indexOf(data); mHighlightBuffer.clear(); for (Highlight h : indices) { if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1) mHighlightBuffer.add(h); } renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()])); } }
Example #11
Source File: CombinedChartRenderer.java From Ticket-Analysis with MIT License | 5 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { Chart chart = mChart.get(); if (chart == null) return; for (DataRenderer renderer : mRenderers) { ChartData data = null; if (renderer instanceof BarChartRenderer) data = ((BarChartRenderer)renderer).mChart.getBarData(); else if (renderer instanceof LineChartRenderer) data = ((LineChartRenderer)renderer).mChart.getLineData(); else if (renderer instanceof CandleStickChartRenderer) data = ((CandleStickChartRenderer)renderer).mChart.getCandleData(); else if (renderer instanceof ScatterChartRenderer) data = ((ScatterChartRenderer)renderer).mChart.getScatterData(); else if (renderer instanceof BubbleChartRenderer) data = ((BubbleChartRenderer)renderer).mChart.getBubbleData(); int dataIndex = data == null ? -1 : ((CombinedData)chart.getData()).getAllData().indexOf(data); mHighlightBuffer.clear(); for (Highlight h : indices) { if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1) mHighlightBuffer.add(h); } renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()])); } }
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: CombinedChartRenderer.java From StockChart-MPAndroidChart with MIT License | 5 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { Chart chart = mChart.get(); if (chart == null) { return; } for (DataRenderer renderer : mRenderers) { ChartData data = null; if (renderer instanceof BarChartRenderer) { data = ((BarChartRenderer) renderer).mChart.getBarData(); } else if (renderer instanceof LineChartRenderer) { data = ((LineChartRenderer) renderer).mChart.getLineData(); } else if (renderer instanceof CandleStickChartRenderer) { data = ((CandleStickChartRenderer) renderer).mChart.getCandleData(); } else if (renderer instanceof ScatterChartRenderer) { data = ((ScatterChartRenderer) renderer).mChart.getScatterData(); } else if (renderer instanceof BubbleChartRenderer) { data = ((BubbleChartRenderer) renderer).mChart.getBubbleData(); } int dataIndex = data == null ? -1 : ((CombinedData) chart.getData()).getAllData().indexOf(data); mHighlightBuffer.clear(); for (Highlight h : indices) { if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1) { mHighlightBuffer.add(h); } } renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()])); } }
Example #14
Source File: CandleStickChartManager.java From react-native-mp-android-chart with MIT License | 4 votes |
@Override ChartData createData(String[] xValues) { return new CandleData(xValues); }
Example #15
Source File: BarChartManager.java From react-native-mp-android-chart with MIT License | 4 votes |
@Override ChartData createData(String[] xValues) { return new BarData(xValues); }
Example #16
Source File: RecordGraphFragment.java From voice-pitch-analyzer with GNU Affero General Public License v3.0 | 4 votes |
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { CombinedChart chart = (CombinedChart) view.findViewById(R.id.recording_chart); pitchDataSet = new LineDataSet(mListener.startingPitchEntries(), getResources().getString(R.string.progress)); // generate x value strings // [1, 2, 3,... basically random numbers as the recorded pitch is based on processor speed] List<String> xVals = ChartData.generateXVals(0, pitchDataSet.getEntryCount()); chartData = new CombinedData(xVals); pitchDataSet.setColor(getResources().getColor(R.color.canvas_dark)); pitchDataSet.setDrawCircles(false); pitchDataSet.setLineWidth(2f); pitchDataSet.setDrawValues(false); pitchDataSet.setAxisDependency(YAxis.AxisDependency.LEFT); pitchData = new LineData(xVals, pitchDataSet); chartData.setData(pitchData); genderBarData = new BarData(xVals, GraphLayout.getOverallRange(this.getContext(), xVals.size())); // Bug with chart lib that throws exception for empty bar charts so must skip adding it on init // if were coming from the live pitch graph. if (!xVals.isEmpty()) chartData.setData(genderBarData); chart.setData(chartData); chart.setDrawValueAboveBar(false); chart.setDrawOrder(new CombinedChart.DrawOrder[]{ CombinedChart.DrawOrder.BAR, CombinedChart.DrawOrder.BUBBLE, CombinedChart.DrawOrder.CANDLE, CombinedChart.DrawOrder.LINE, CombinedChart.DrawOrder.SCATTER }); GraphLayout.FormatChart(chart); super.onViewCreated(view, savedInstanceState); }
Example #17
Source File: BubbleChartManager.java From react-native-mp-android-chart with MIT License | 4 votes |
@Override ChartData createData(String[] xValues) { return new BubbleData(xValues); }
Example #18
Source File: ScatterChartManager.java From react-native-mp-android-chart with MIT License | 4 votes |
@Override ChartData createData(String[] xValues) { return new ScatterData(xValues); }
Example #19
Source File: PieChartManager.java From react-native-mp-android-chart with MIT License | 4 votes |
@Override ChartData createData(String[] xValues) { return new PieData(xValues); }
Example #20
Source File: RadarChartManager.java From react-native-mp-android-chart with MIT License | 4 votes |
@Override ChartData createData(String[] xValues) { return new RadarData(xValues); }
Example #21
Source File: BarChartItem.java From Stayfit with Apache License 2.0 | 4 votes |
public BarChartItem(ChartData<?> cd, Context c) { super(cd); mTf = Typeface.createFromAsset(c.getAssets(), "OpenSans-Regular.ttf"); }
Example #22
Source File: LineChartItem.java From Stayfit with Apache License 2.0 | 4 votes |
public LineChartItem(ChartData<?> cd, Context c) { super(cd); mTf = Typeface.createFromAsset(c.getAssets(), "OpenSans-Regular.ttf"); }
Example #23
Source File: PieChartItem.java From Stayfit with Apache License 2.0 | 4 votes |
public PieChartItem(ChartData<?> cd, Context c) { super(cd); mTf = Typeface.createFromAsset(c.getAssets(), "OpenSans-Regular.ttf"); mCenterText = generateCenterText(); }
Example #24
Source File: ChartItem.java From Stayfit with Apache License 2.0 | 4 votes |
public ChartItem(ChartData<?> cd) { this.mChartData = cd; }
Example #25
Source File: LineChartManager.java From react-native-mp-android-chart with MIT License | 4 votes |
@Override ChartData createData(String[] xValues) { return new LineData(xValues); }
Example #26
Source File: PieChartItem.java From memorize with MIT License | 4 votes |
public PieChartItem(ChartData<?> cd, Context c) { super(cd); mCenterText = generateCenterText(); }
Example #27
Source File: ChartItem.java From memorize with MIT License | 4 votes |
ChartItem(ChartData<?> cd) { this.mChartData = cd; }
Example #28
Source File: LineChartItem.java From memorize with MIT License | 4 votes |
public LineChartItem(ChartData<?> cd, Context c) { super(cd); }
Example #29
Source File: BarChartItem.java From memorize with MIT License | 4 votes |
public BarChartItem(ChartData<?> cd, Context c) { super(cd); }
Example #30
Source File: ChartItem.java From StockChart-MPAndroidChart with MIT License | 4 votes |
ChartItem(ChartData<?> cd) { this.mChartData = cd; }