[英]How can I show custom view as marker by default on Charts in iOS
I am using Charts SDK to show Line graph in my app.我正在使用 Charts SDK 在我的应用程序中显示折线图。 I want to display marker for some coordinates of graph by default, (ie, when graph is loaded then by default a custom view marker should be displayed above some coordinates of graph).
默认情况下,我想为图形的某些坐标显示标记(即,当加载图形时,默认情况下,自定义视图标记应显示在图形的某些坐标上方)。
I am able to do it when graph is touched and delegate method of Chart SDK is called触摸图形并调用 Chart SDK 的委托方法时,我可以执行此操作
chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight)
But, how can i achieve this by default without touching the graph .但是,如何在不触及图形的情况下默认实现这一点。
I also used LineChartDataSet
but it shows circle for those values, but i want to show some custom view instead of circle.我也使用了
LineChartDataSet
但它显示了这些值的圆圈,但我想显示一些自定义视图而不是圆圈。
Thank you谢谢
You can set a custom icon for data entries by using ChartDataEntry(x:, y:, icon:)
initializer您可以使用
ChartDataEntry(x:, y:, icon:)
初始值设定项为数据条目设置自定义图标
let entry = ChartDataEntry(x: 2, y: 12, icon: UIImage(systemName: "airplane.circle.fill"))
Make sure you have also lineDataSet.drawIconsEnabled = true
确保你也有
lineDataSet.drawIconsEnabled = true
let lineDataSet = LineChartDataSet(....)
lineDataSet.drawIconsEnabled = true
as answered by @SamB.正如@SamB 所回答的那样。 I am using Charts SDK in my iOS project.
我在 iOS 项目中使用 Charts SDK。 Charts SDK provides functionality to pass image
Charts SDK 提供了传递图像的功能
ChartDataEntry(x: 10, y: 10, data: 20, icon: UIImage(systemName: "imageName"))
In Data field you can paas the position value of those point.在数据字段中,您可以设置这些点的位置值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.