我希望我的图表能像图片一样有两个不同刻度的Y轴。我该如何更改每个轴的刻度?
上周末发布了2.0.0-beta版本,其中包含一个CombinedChart
,可以在一个图表中绘制折线图、柱状图、散点图和蜡烛图。所以该功能终于可用了。
关于我的升级发现,你不能简单地为每个数据集添加addDataSet()
,你必须生成各个数据集类型(柱状图、折线图、散点图等),然后使用SetData()
为适当的类型触发渲染。
这是示例代码。
MPAndroidChart库的作者在这里清楚地指出(MPChart - 散点图和线性图在同一绘图中),该功能尚未可用。因此,我也在寻找更好的方法。
因此,您可以使用此库将两种不同的图表类型显示为一个图表,只需重叠它们即可。
我已经按照以下方式完成了此操作:
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!
mpandroidcharts
建议的一切都做了。 combinedChart.axisLeft?.axisMinimum = //some calculations
combinedChart.axisLeft?.axisMaximum = //some calculations
combinedChart.axisRight?.axisMinimum = //some calculations
combinedChart.axisRight?.axisMaximum = //some calculations
基本上是复制粘贴错误,当你从柱状图或线图中复制你的完美代码时,在设置轴最小值和最大值的位置出现了问题。