gpt4 book ai didi

android - 使用 MpAndroidChart-CombinedChart,如何将图表分成上下两部分?

转载 作者:行者123 更新时间:2023-12-03 17:28:52 27 4
gpt4 key购买 nike

在下图中,我绘制了一天的价格和每小时的交易量。
为了实现这一点,我使用了 CombinedChart类型。您可以立即看到交易量数据分散了用户对价格数据的注意力,因为两个图表都填满了屏幕。

问题:
有没有办法保留图表底部的 25% 的成交量和图表顶部的 75% 的价格?

bitcoin prices and volume

代码如下:

private void setupChart(){
chart.setAutoScaleMinMaxEnabled(true);
chart.setBackgroundColor(Color.WHITE);
chart.getDescription().setEnabled(false);
chart.setPinchZoom(false);
chart.setDrawGridBackground(false);
chart.getLegend().setEnabled(true);
chart.setDrawOrder(new CombinedChart.DrawOrder[]{ CombinedChart.DrawOrder.BAR, CombinedChart.DrawOrder.CANDLE });// draw bars behind candles

// right side is for the volume
YAxis rightAxis = chart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setAxisMinimum(0f);
}

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
chart.resetTracking();

ArrayList<HistoricPrice> historicPrices = presenter.getHistoricalDataGranular(DEFAULT_GRANULARITY_MINS);

ArrayList<CandleEntry> valuesCandles = new ArrayList<>();
ArrayList<BarEntry> valuesBars = new ArrayList<>();


for (int i = progress; (i < progress+MAX_CANDLES_COUNT) && (i < historicPrices.size()); i++) {
HistoricPrice historicPrice = historicPrices.get(i);
CandleEntry candleEntry = new CandleEntry(i, historicPrice.high.floatValue(), historicPrice.low.floatValue(), historicPrice.open.floatValue(), historicPrice.close.floatValue());
valuesCandles.add(candleEntry);
BarEntry barEntry = new BarEntry(i, Float.valueOf(historicPrice.volume.toPlainString()));
valuesBars.add(barEntry);
}

CandleDataSet set1 = new CandleDataSet(valuesCandles, "Prices");
set1.setDrawIcons(false);
set1.setAxisDependency(YAxis.AxisDependency.LEFT);
set1.setShadowColor(Color.DKGRAY);
set1.setShadowWidth(0.7f);
set1.setDecreasingColor(Color.RED);
set1.setDecreasingPaintStyle(Paint.Style.FILL);
set1.setIncreasingColor(Color.rgb(122, 242, 84));
set1.setIncreasingPaintStyle(Paint.Style.FILL);
set1.setNeutralColor(Color.BLUE);
set1.setDrawValues(true);
set1.setShowCandleBar(true);
CandleData candleData = new CandleData(set1);

BarDataSet set2 = new BarDataSet(valuesBars, "Volume");
set2.setColor(ContextCompat.getColor(this, R.color.blue_grey));
set2.setDrawValues(true);
set2.setAxisDependency(YAxis.AxisDependency.RIGHT);
BarData barData = new BarData(set2);

CombinedData data = new CombinedData();
data.setData(candleData);
data.setData(barData);


chart.setData(data);
chart.invalidate();
}

最佳答案

您可以设置数据集是否依赖于 leftAxis 或 rightAxis。因此,您将 set1 设置为依赖 leftAxis,将 set2 设置为 RightAxis。完成此操作后,此调用 set1.getAxisLeft().setAxisMinimum(minValue) 将从图形开始的位置开始。
看看下面的 fragment

CandleDataSet set1 = new CandleDataSet(valuesCandles, "Prices");
set1.setAxisDependency(YAxis.AxisDependency.LEFT);
set1.getAxisLeft().setAxisMinimum(minValue)

BarDataSet set2 = new BarDataSet(valuesBars, "Volume");
set2.setAxisDependency(YAxis.AxisDependency.RIGHT);

关于android - 使用 MpAndroidChart-CombinedChart,如何将图表分成上下两部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57931038/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com