我希望我的图表有两个不同比例的Y轴,如图像。我如何改变每个轴的比例?
答案 0 :(得分:5)
Version 2.0.0-beta周末以CombinedChart
发布,允许在一个图表中绘制Line-,Bar-,Scatter-和CandleData。所以该功能最终可用。
关于我在升级期间发现的内容的一个注意事项,你不能简单地为每一个添加dataSet(),你必须生成各个DataSet类型(Bar,Line,Scatter等),然后使用SetData()适当的类型,以触发渲染。
这是example code。
答案 1 :(得分:4)
MPAndroidChart库的作者在此明确指出(MPChart - Scatter Chart and LineChart in same plot),此功能尚不可用。所以,我也在寻找一种更好的方法。
因此,您可以将两种不同的图表类型显示为一种,仍然使用此库,只能通过重叠它们。
我已经在我这边做了以下事情:
1。编辑活动布局xml,将FrameLayout作为图表容器。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
.......
<FrameLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/root_view">
</FrameLayout>
.......
</LinearLayout>
// construct the charts, as different objects
// make sure to have valid Data Sets
LineChartItem lineChart = new LineChartItem(lineChartDataset, getApplicationContext());
BarChartItem barChart = new BarChartItem(barChartDataset, getApplicationContext());
// get the charts' container
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.root_view);
// populate the container with the charts' views
frameLayout.addView(lineChart.getView(0, null, getApplicationContext()));
frameLayout.addView(barChart.getView(1, null, getApplicationContext()));
对于这种做法, PROs / CONs :
赞成的
我希望快速发布这个有这个选项的优秀文库。提前谢谢Philipp Jahoda!
答案 2 :(得分:0)
就我而言,我会按照mpandroidcharts
仍然在“ y轴右”和“ y轴左”
上获得相同的比例罪魁祸首是
combinedChart.axisLeft?.axisMinimum = //some calculations
combinedChart.axisLeft?.axisMaximum = //some calculations
combinedChart.axisRight?.axisMinimum = //some calculations
combinedChart.axisRight?.axisMaximum = //some calculations
从条形图或折线图中复制 perfect 代码时,基本上是复制粘贴错误,其中在需要的地方设置轴的最小值和最大值。