Java Code Examples for com.github.mikephil.charting.data.CombinedData#setData()
The following examples show how to use
com.github.mikephil.charting.data.CombinedData#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: KLineChart.java From StockChart-MPAndroidChart with MIT License | 6 votes |
/** * 副图指标成交量 */ public void setVolumeToChart() { if (barChart != null) { if (barChart.getBarData() != null) { barChart.getBarData().clearValues(); } if (barChart.getLineData() != null) { barChart.getLineData().clearValues(); } if (barChart.getCandleData() != null) { barChart.getCandleData().clearValues(); } axisLeftBar.resetAxisMaximum(); axisLeftBar.resetAxisMinimum(); axisLeftBar.setAxisMinimum(0); axisLeftBar.setValueFormatter(new VolFormatter(mContext, kLineData.getAssetId())); CombinedData combinedData = barChart.getData(); combinedData.setData(new BarData(kLineData.getVolumeDataSet())); combinedData.setData(new LineData()); barChart.notifyDataSetChanged(); barChart.animateY(1000); } }
Example 2
Source File: TimeLineView.java From android-kline with Apache License 2.0 | 6 votes |
private void initChartVolumeData() { ArrayList<BarEntry> barEntries = new ArrayList<>(); ArrayList<BarEntry> paddingEntries = new ArrayList<>(); for (int i = 0; i < mData.size(); i++) { HisData t = mData.get(i); barEntries.add(new BarEntry(i, (float) t.getVol(), t)); } int maxCount = MAX_COUNT; if (!mData.isEmpty() && mData.size() < maxCount) { for (int i = mData.size(); i < maxCount; i++) { paddingEntries.add(new BarEntry(i, 0)); } } BarData barData = new BarData(setBar(barEntries, NORMAL_LINE), setBar(paddingEntries, INVISIABLE_LINE)); barData.setBarWidth(0.75f); CombinedData combinedData = new CombinedData(); combinedData.setData(barData); mChartVolume.setData(combinedData); mChartVolume.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartVolume.notifyDataSetChanged(); mChartVolume.moveViewToX(combinedData.getEntryCount()); }
Example 3
Source File: KLineChart.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * 副图指标MACD */ public void setMACDToChart() { if (barChart != null) { if (barChart.getBarData() != null) { barChart.getBarData().clearValues(); } if (barChart.getLineData() != null) { barChart.getLineData().clearValues(); } if (barChart.getCandleData() != null) { barChart.getCandleData().clearValues(); } axisLeftBar.resetAxisMaximum(); axisLeftBar.resetAxisMinimum(); axisLeftBar.setValueFormatter(new ValueFormatter() { @Override public String getAxisLabel(float value, AxisBase axis) { return NumberUtils.keepPrecision(value, precision); } }); CombinedData combinedData = barChart.getData(); combinedData.setData(new LineData(kLineData.getLineDataMACD())); combinedData.setData(new BarData(kLineData.getBarDataMACD())); barChart.notifyDataSetChanged(); barChart.invalidate(); } }
Example 4
Source File: StatisticsFragment.java From HeartBeat with Apache License 2.0 | 5 votes |
@Override protected Void doInBackground(Void... params) { StopWatch watch = new StopWatch(TAG, UpdateChartTask.class.getSimpleName()); mCombinedData = new CombinedData(TimeUtils.getWeekDateString()); mCombinedData.setData(getWeekEventData()); mCombinedData.setData(getWeekThoughtData()); watch.stop(); return null; }
Example 5
Source File: CombinedChartActivity.java From Stayfit with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_combined); mChart = (CombinedChart) findViewById(R.id.chart1); mChart.setDescription(""); mChart.setBackgroundColor(Color.WHITE); mChart.setDrawGridBackground(false); mChart.setDrawBarShadow(false); // draw bars behind lines mChart.setDrawOrder(new DrawOrder[] { DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER }); YAxis rightAxis = mChart.getAxisRight(); rightAxis.setDrawGridLines(false); rightAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true) YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setDrawGridLines(false); leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true) XAxis xAxis = mChart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTH_SIDED); CombinedData data = new CombinedData(mMonths); data.setData(generateLineData()); data.setData(generateBarData()); // data.setData(generateBubbleData()); // data.setData(generateScatterData()); // data.setData(generateCandleData()); mChart.setData(data); mChart.invalidate(); }
Example 6
Source File: KLineView.java From android-kline with Apache License 2.0 | 5 votes |
private void initChartKdjData() { ArrayList<Entry> kEntries = new ArrayList<>(INIT_COUNT); ArrayList<Entry> dEntries = new ArrayList<>(INIT_COUNT); ArrayList<Entry> jEntries = new ArrayList<>(INIT_COUNT); ArrayList<Entry> paddingEntries = new ArrayList<>(INIT_COUNT); for (int i = 0; i < mData.size(); i++) { kEntries.add(new Entry(i, (float) mData.get(i).getK())); dEntries.add(new Entry(i, (float) mData.get(i).getD())); jEntries.add(new Entry(i, (float) mData.get(i).getJ())); } if (!mData.isEmpty() && mData.size() < MAX_COUNT) { for (int i = mData.size(); i < MAX_COUNT; i++) { paddingEntries.add(new Entry(i, (float) mData.get(mData.size() - 1).getK())); } } ArrayList<ILineDataSet> sets = new ArrayList<>(); sets.add(setLine(K, kEntries)); sets.add(setLine(D, dEntries)); sets.add(setLine(J, jEntries)); sets.add(setLine(INVISIABLE_LINE, paddingEntries)); LineData lineData = new LineData(sets); CombinedData combinedData = new CombinedData(); combinedData.setData(lineData); mChartKdj.setData(combinedData); mChartMacd.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartKdj.notifyDataSetChanged(); moveToLast(mChartKdj); }
Example 7
Source File: KLineView.java From android-kline with Apache License 2.0 | 5 votes |
private void initChartMacdData() { ArrayList<BarEntry> barEntries = new ArrayList<>(); ArrayList<BarEntry> paddingEntries = new ArrayList<>(); ArrayList<Entry> difEntries = new ArrayList<>(); ArrayList<Entry> deaEntries = new ArrayList<>(); for (int i = 0; i < mData.size(); i++) { HisData t = mData.get(i); barEntries.add(new BarEntry(i, (float) t.getMacd())); difEntries.add(new Entry(i, (float) t.getDif())); deaEntries.add(new Entry(i, (float) t.getDea())); } int maxCount = MAX_COUNT; if (!mData.isEmpty() && mData.size() < maxCount) { for (int i = mData.size(); i < maxCount; i++) { paddingEntries.add(new BarEntry(i, 0)); } } BarData barData = new BarData(setBar(barEntries, NORMAL_LINE), setBar(paddingEntries, INVISIABLE_LINE)); barData.setBarWidth(0.75f); CombinedData combinedData = new CombinedData(); combinedData.setData(barData); LineData lineData = new LineData(setLine(DIF, difEntries), setLine(DEA, deaEntries)); combinedData.setData(lineData); mChartMacd.setData(combinedData); mChartMacd.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartMacd.notifyDataSetChanged(); // mChartMacd.moveViewToX(combinedData.getEntryCount()); moveToLast(mChartMacd); }
Example 8
Source File: KLineView.java From android-kline with Apache License 2.0 | 5 votes |
private void initChartVolumeData() { ArrayList<BarEntry> barEntries = new ArrayList<>(); ArrayList<BarEntry> paddingEntries = new ArrayList<>(); for (int i = 0; i < mData.size(); i++) { HisData t = mData.get(i); barEntries.add(new BarEntry(i, (float) t.getVol(), t)); } int maxCount = MAX_COUNT; if (!mData.isEmpty() && mData.size() < maxCount) { for (int i = mData.size(); i < maxCount; i++) { paddingEntries.add(new BarEntry(i, 0)); } } BarData barData = new BarData(setBar(barEntries, NORMAL_LINE), setBar(paddingEntries, INVISIABLE_LINE)); barData.setBarWidth(0.75f); CombinedData combinedData = new CombinedData(); combinedData.setData(barData); mChartVolume.setData(combinedData); mChartVolume.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartVolume.notifyDataSetChanged(); // mChartVolume.moveViewToX(combinedData.getEntryCount()); moveToLast(mChartVolume); }
Example 9
Source File: KLineChart.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * 副图指标RSI */ public void setRSIToChart() { if (barChart != null) { if (barChart.getBarData() != null) { barChart.getBarData().clearValues(); } if (barChart.getLineData() != null) { barChart.getLineData().clearValues(); } if (barChart.getCandleData() != null) { barChart.getCandleData().clearValues(); } axisLeftBar.resetAxisMaximum(); axisLeftBar.resetAxisMinimum(); axisLeftBar.setValueFormatter(new ValueFormatter() { @Override public String getAxisLabel(float value, AxisBase axis) { return NumberUtils.keepPrecision(value, precision); } }); CombinedData combinedData = barChart.getData(); combinedData.setData(new LineData(kLineData.getLineDataRSI())); barChart.notifyDataSetChanged(); barChart.invalidate(); } }
Example 10
Source File: KLineChart.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * 副图指标BOLL */ public void setBOLLToChart() { if (barChart != null) { if (barChart.getBarData() != null) { barChart.getBarData().clearValues(); } if (barChart.getLineData() != null) { barChart.getLineData().clearValues(); } if (barChart.getCandleData() != null) { barChart.getCandleData().clearValues(); } axisLeftBar.resetAxisMaximum(); axisLeftBar.resetAxisMinimum(); axisLeftBar.setValueFormatter(new ValueFormatter() { @Override public String getAxisLabel(float value, AxisBase axis) { return NumberUtils.keepPrecision(value, precision); } }); CombinedData combinedData = barChart.getData(); combinedData.setData(new CandleData(kLineData.getBollCandleDataSet())); combinedData.setData(new LineData(kLineData.getLineDataBOLL())); barChart.notifyDataSetChanged(); barChart.invalidate(); } }
Example 11
Source File: KLineChart.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * 副图指标KDJ */ public void setKDJToChart() { if (barChart != null) { if (barChart.getBarData() != null) { barChart.getBarData().clearValues(); } if (barChart.getLineData() != null) { barChart.getLineData().clearValues(); } if (barChart.getCandleData() != null) { barChart.getCandleData().clearValues(); } axisLeftBar.resetAxisMaximum(); axisLeftBar.resetAxisMinimum(); axisLeftBar.setValueFormatter(new ValueFormatter() { @Override public String getAxisLabel(float value, AxisBase axis) { return NumberUtils.keepPrecision(value, precision); } }); CombinedData combinedData = barChart.getData(); combinedData.setData(new LineData(kLineData.getLineDataKDJ())); barChart.notifyDataSetChanged(); barChart.invalidate(); } }
Example 12
Source File: TimeLineView.java From android-kline with Apache License 2.0 | 4 votes |
public void initDatas(List<HisData>... hisDatas) { // 设置标签数量,并让标签居中显示 XAxis xAxis = mChartVolume.getXAxis(); xAxis.setLabelCount(hisDatas.length + 1, true); xAxis.setAvoidFirstLastClipping(false); xAxis.setCenterAxisLabels(true); xAxis.setValueFormatter(new IAxisValueFormatter() { @Override public String getFormattedValue(float value, AxisBase axis) { value += 1; // 这里不设置+1会有bug if (mData.isEmpty()) { return ""; } if (value < 0) { value = 0; } if (value < mData.size()) { return DateUtils.formatDate(mData.get((int) value).getDate(), mDateFormat); } return ""; } }); mData.clear(); ArrayList<ILineDataSet> sets = new ArrayList<>(); ArrayList<IBarDataSet> barSets = new ArrayList<>(); for (List<HisData> hisData : hisDatas) { hisData = DataUtils.calculateHisData(hisData); ArrayList<Entry> priceEntries = new ArrayList<>(INIT_COUNT); ArrayList<Entry> aveEntries = new ArrayList<>(INIT_COUNT); ArrayList<Entry> paddingEntries = new ArrayList<>(INIT_COUNT); ArrayList<BarEntry> barPaddingEntries = new ArrayList<>(INIT_COUNT); ArrayList<BarEntry> barEntries = new ArrayList<>(INIT_COUNT); for (int i = 0; i < hisData.size(); i++) { HisData t = hisData.get(i); priceEntries.add(new Entry(i + mData.size(), (float) t.getClose())); aveEntries.add(new Entry(i + mData.size(), (float) t.getAvePrice())); barEntries.add(new BarEntry(i + mData.size(), (float) t.getVol(), t)); } if (!hisData.isEmpty() && hisData.size() < INIT_COUNT / hisDatas.length) { for (int i = hisData.size(); i < INIT_COUNT / hisDatas.length; i++) { paddingEntries.add(new Entry(i, (float) hisData.get(hisData.size() - 1).getClose())); barPaddingEntries.add(new BarEntry(i, (float) hisData.get(hisData.size() - 1).getClose())); } } sets.add(setLine(NORMAL_LINE_5DAY, priceEntries)); sets.add(setLine(AVE_LINE, aveEntries)); sets.add(setLine(INVISIABLE_LINE, paddingEntries)); barSets.add(setBar(barEntries, NORMAL_LINE)); barSets.add(setBar(barPaddingEntries, INVISIABLE_LINE)); barSets.add(setBar(barPaddingEntries, INVISIABLE_LINE)); mData.addAll(hisData); } LineData lineData = new LineData(sets); CombinedData combinedData = new CombinedData(); combinedData.setData(lineData); mChartPrice.setData(combinedData); mChartPrice.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartPrice.notifyDataSetChanged(); // mChartPrice.moveViewToX(combinedData.getEntryCount()); moveToLast(mChartVolume); BarData barData = new BarData(barSets); barData.setBarWidth(0.75f); CombinedData combinedData2 = new CombinedData(); combinedData2.setData(barData); mChartVolume.setData(combinedData2); mChartVolume.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartVolume.notifyDataSetChanged(); mChartVolume.moveViewToX(combinedData2.getEntryCount()); mChartPrice.getXAxis().setAxisMaximum(combinedData.getXMax() + 0.5f); mChartVolume.getXAxis().setAxisMaximum(mChartVolume.getData().getXMax() + 0.5f); mChartPrice.zoom(MAX_COUNT * 1f / INIT_COUNT, 0, 0, 0); mChartVolume.zoom(MAX_COUNT * 1f / INIT_COUNT, 0, 0, 0); setDescription(mChartVolume, "成交量 " + getLastData().getVol()); }
Example 13
Source File: TimeLineView.java From android-kline with Apache License 2.0 | 4 votes |
public void initData(List<HisData> hisDatas) { mData.clear(); mData.addAll(DataUtils.calculateHisData(hisDatas)); ArrayList<Entry> priceEntries = new ArrayList<>(INIT_COUNT); ArrayList<Entry> aveEntries = new ArrayList<>(INIT_COUNT); ArrayList<Entry> paddingEntries = new ArrayList<>(INIT_COUNT); for (int i = 0; i < mData.size(); i++) { priceEntries.add(new Entry(i, (float) mData.get(i).getClose())); aveEntries.add(new Entry(i, (float) mData.get(i).getAvePrice())); } if (!mData.isEmpty() && mData.size() < MAX_COUNT) { for (int i = mData.size(); i < MAX_COUNT; i++) { paddingEntries.add(new Entry(i, (float) mData.get(mData.size() - 1).getClose())); } } ArrayList<ILineDataSet> sets = new ArrayList<>(); sets.add(setLine(NORMAL_LINE, priceEntries)); sets.add(setLine(AVE_LINE, aveEntries)); sets.add(setLine(INVISIABLE_LINE, paddingEntries)); LineData lineData = new LineData(sets); CombinedData combinedData = new CombinedData(); combinedData.setData(lineData); mChartPrice.setData(combinedData); mChartPrice.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartPrice.notifyDataSetChanged(); // mChartPrice.moveViewToX(combinedData.getEntryCount()); moveToLast(mChartPrice); initChartVolumeData(); mChartPrice.getXAxis().setAxisMaximum(combinedData.getXMax() + 0.5f); mChartVolume.getXAxis().setAxisMaximum(mChartVolume.getData().getXMax() + 0.5f); mChartPrice.zoom(MAX_COUNT * 1f / INIT_COUNT, 0, 0, 0); mChartVolume.zoom(MAX_COUNT * 1f / INIT_COUNT, 0, 0, 0); setDescription(mChartVolume, "成交量 " + getLastData().getVol()); }
Example 14
Source File: CombinedChartActivity.java From StockChart-MPAndroidChart with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_combined); setTitle("CombinedChartActivity"); chart = findViewById(R.id.chart1); chart.getDescription().setEnabled(false); chart.setBackgroundColor(Color.WHITE); chart.setDrawGridBackground(false); chart.setDrawBarShadow(false); chart.setHighlightFullBarEnabled(false); // draw bars behind lines chart.setDrawOrder(new DrawOrder[]{ DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER }); Legend l = chart.getLegend(); l.setWordWrapEnabled(true); l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER); l.setOrientation(Legend.LegendOrientation.HORIZONTAL); l.setDrawInside(false); YAxis rightAxis = chart.getAxisRight(); rightAxis.setDrawGridLines(false); rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true) YAxis leftAxis = chart.getAxisLeft(); leftAxis.setDrawGridLines(false); leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true) XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTH_SIDED); xAxis.setAxisMinimum(0f); xAxis.setGranularity(1f); xAxis.setValueFormatter(new ValueFormatter() { @Override public String getFormattedValue(float value) { return months[(int) value % months.length]; } }); CombinedData data = new CombinedData(); data.setData(generateLineData()); data.setData(generateBarData()); data.setData(generateBubbleData()); data.setData(generateScatterData()); data.setData(generateCandleData()); data.setValueTypeface(tfLight); xAxis.setAxisMaximum(data.getXMax() + 0.25f); chart.setData(data); chart.invalidate(); }
Example 15
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 16
Source File: ProgressFragment.java From voice-pitch-analyzer with GNU Affero General Public License v3.0 | 4 votes |
@Override public void onViewCreated(View view, Bundle savedInstanceState) { CombinedChart chart = (CombinedChart) view.findViewById(R.id.progress_chart); this.recordings = new RecordingList(this.getContext()); if (this.recordings != null) { List<String> dates = this.recordings.getDates(); CombinedData data = new CombinedData(dates); LineDataSet dataSet = new LineDataSet(this.recordings.getGraphEntries(), getResources().getString(R.string.progress)); LineData lineData = new LineData(dates, dataSet); BarData barData = new BarData(dates, GraphLayout.getOverallRange(this.getContext(), dates.size())); dataSet.setDrawCubic(true); dataSet.enableDashedLine(10, 10, 0); dataSet.setLineWidth(3f); dataSet.setDrawValues(false); dataSet.setCircleColor(getResources().getColor(R.color.canvas_dark)); dataSet.setColor(getResources().getColor(R.color.canvas_dark)); dataSet.setCircleSize(5f); dataSet.setCubicIntensity(0.05f); dataSet.setAxisDependency(YAxis.AxisDependency.LEFT); data.setData(lineData); data.setData(barData); chart.setData(data); GraphLayout.FormatChart(chart); chart.setTouchEnabled(true); // chart.setScaleEnabled(true); chart.setPinchZoom(true); // chart.setDoubleTapToZoomEnabled(true); chart.setDrawValueAboveBar(false); chart.setDrawOrder(new DrawOrder[]{ DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER }); } super.onViewCreated(view, savedInstanceState); }
Example 17
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); }