如何在danielgindi iOS图表中创建多个y轴折线图? [英] How to create multiple y-axis Line chart in danielgindi iOS chart?
问题描述
我想创建一个具有多个y轴的图形.在 danielgindi 图表中可以使用Duel y轴图,但我想要更多两个y轴图.如下图所示:
I want to create a graph with multiple y-axis. Duel y-axis graph is possible in danielgindi chart but I want more the two y-axis graph. Like below image:
let set1 = LineChartDataSet(values: yVals1, label: "DataSet 1")
set1.axisDependency = .left
set1.setColor(UIColor(red: 51/255, green: 181/255, blue: 229/255, alpha: 1))
set1.setCircleColor(.white)
set1.lineWidth = 2
set1.circleRadius = 3
set1.fillAlpha = 65/255
set1.fillColor = UIColor(red: 51/255, green: 181/255, blue: 229/255, alpha: 1)
set1.highlightColor = UIColor(red: 244/255, green: 117/255, blue: 117/255, alpha: 1)
set1.drawCircleHoleEnabled = false
let set2 = LineChartDataSet(values: yVals2, label: "DataSet 2")
set2.axisDependency = .right
set2.setColor(.red)
set2.setCircleColor(.white)
set2.lineWidth = 2
set2.circleRadius = 3
set2.fillAlpha = 65/255
set2.fillColor = .red
set2.highlightColor = UIColor(red: 244/255, green: 117/255, blue: 117/255, alpha: 1)
set2.drawCircleHoleEnabled = false
这是danielgindi图表代码,但在此代码中显示了双y轴.
This the danielgindi chart code but in this code show double y axis.
我该怎么办? 预先感谢.
How can I do? Thanks in advance.
推荐答案
我只是快速浏览了一下代码,简短的回答是仅支持两个轴,我想您可以猜测一下,因为该轴依赖性是具有两个选项的枚举.
I just had a quick look at the code and the short answer is that only two axis are supported, and I think you can kind of guess this because the axis dependency is an enumeration with two options.
如果您仍然想制作三轴图,则可以通过自定义类和/或数据准备来解决某些限制.
If you still want to do a three axis graph, you can work around some of this limitation with custom classes and/or data preparation.
您可以使用自定义格式器在每个轴点上打印两个标签,从而将其中一张图上的标签加倍.它的外观取决于您的轴.达到完全独立的自动量程将是一个很大的问题.
You can double up the labels on one of the graphs by using a custom formatter to print two labels at each axis point. How good it looks depends on your axis. Getting to full independent auto-ranging would be a big ask.
您不能对不同的数据集使用不同的比例尺,因为转换是由DataProvider根据相关轴而不是数据集提供的.
相对于第三轴绘制数据集要复杂得多,但并非如此.快速查看渲染器代码会发现,渲染代码会根据相关轴要求数据集进行转换,以将数据值转换为像素值.通过覆盖
You can't use different scales for different data sets, because the transform is provided by the DataProvider, based on the dependent axis, not by the data set.
Plotting a data set against a third axis is a bit more involved, but not horribly so. A quick look at the renderer code shows that the render code asks the data set for a transform to translate data values into pixel values, based on the dependent axis. By overriding
func getTransformer(forAxis轴:YAxis.AxisDependency)->变压器
func getTransformer(forAxis axis: YAxis.AxisDependency) -> Transformer
在您的自定义数据集中,您可以让渲染器使用不同的y-scale/transform渲染数据值.
in your custom dataset, you can have the renderer render your data values using a different y-scale/transform.
或者,您可以将两个数据集的源数据转换为0-1(例如)的范围,然后再转换回以在自定义格式器中进行轴标记.这样会破坏数据值标签,但是在您的示例中我看不到您使用它们.
Alternatively, you can transform your source data for two of your data sets to range from 0-1 (e.g.), and then transform back for axis labelling in your custom formatter. This breaks data value labels, but I don't see you using them in your example.
希望这会有所帮助
这篇关于如何在danielgindi iOS图表中创建多个y轴折线图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!