简体   繁体   English

带有固定X轴标签的折线图,例如iOS中的healthkit图

[英]Line chart with fix X axis label like healthkit graph in iOS

在此处输入图片说明 hello I want to create line chart similar to healthkit. 你好,我想创建类似于healthkit的折线图。 For example i have on X axis (Jul 14, 15, 16, 17), Y axis (0, 50, 100) and data set in (x,y) format is ((jul 15, 30),(jul 17, 80)) I try following libraries 例如,我在X轴(Jul 14,15,16,17),Y轴(0,50,100)上具有(x,y)格式设置的数据是((jul 15,30),(jul 17, 80))我尝试关注图书馆

https://github.com/Boris-Em/BEMSimpleLineGraph/tree/master/Sample%20Project/SimpleLineChart https://github.com/Boris-Em/BEMSimpleLineGraph/tree/master/Sample%20Project/SimpleLineChart

https://github.com/core-plot/core-plot https://github.com/core-plot/core-plot

but all populate x axis based on data set. 但所有数据均基于数据集填充x轴。 ie all library only take parameter for data set based on that x axis and y axis labels are populated. 即,所有库仅基于填充了x轴和y轴标签的数据集采用参数。 Can you please suggest any other library through which I can achieve similar as explain above line chart. 您能否建议我可以通过它实现与上述折线图类似的任何其他库。 Thanks in advance. 提前致谢。

最后,当我没有输入值时(7月15日,BEMNullGraphValue),我使用https://github.com/Boris-Em/BEMSimpleLineGraph/tree/master/Sample%20Project/SimpleLineChart解决了我的问题。

Even this you could do it in your existing graph 即使这样,您也可以在现有图形中完成

Consider below example. 考虑下面的例子。 - {[0,5],[1,5],[3,5],[4,5]} -{[0,5],[1,5],[3,5],[4,5]}

See there is no value for 2, so line chart will draw 0-5 to 1-5 then gap then 3-5 to 4-5. 看到2没有值,因此折线图将绘制0-5到1-5,然后绘制间隙,然后绘制3-5到4-5。

I hope now you could figure out. 我希望现在你能弄清楚。

Still if you wish then get below graph library. 仍然,如果您愿意的话,请进入图库。

Do it with https://github.com/danielgindi/Charts https://github.com/danielgindi/Charts来做

There are many properties like clip, scale, min, max etc for line chart. 折线图有很多属性,例如剪辑,比例,最小,最大等。

Using though properties you could achieve. 使用可以实现的属性。

https://github.com/danielgindi/Charts/issues/533 https://github.com/danielgindi/Charts/issues/533

Edited answer 编辑答案

After doing some work around, i found the way. 经过一些工作后,我找到了方法。

Download sample code 下载示例代码

let months = ["July 14", "15", "16", "17", "18", "19", "20"]
let unitsSold = [0.0, 0.0, 0.0, 100.0, 25.0, 50.0, 75.0]

for i in 0..<dataPoints.count {
    if !values[i].isZero {
        let dataEntry = ChartDataEntry(value: Double(values[i]), xIndex: i)
            dataEntries.append(dataEntry)
    }
}

Refer attached screen shot 请参阅随附的屏幕截图

在此处输入图片说明

In PNChart create one array of indexes which you want to skip the value. 在PNChart中,创建一个要跳过该值的索引数组。 Put condition drawdot funtion on start of for loop of data array if array contain index value then continue. 如果数组包含索引值,则将条件drawdot函数放在数据数组的for循环的开始处,然后继续。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM