简体   繁体   English

如何在 iOS 中的图表上默认将自定义视图显示为标记

[英]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.

相关问题 如何在 ios-charts 上添加标记? - How can I add a Marker on ios-charts? 如何在 ios-charts 中创建气球标记 xib 视图? - How to create Balloon Marker xib View in ios-charts? 如何使用 xib 创建自定义 ios-charts 高亮标记? - How to create a custom ios-charts highlight marker with xib? 如何在iOS Swift中使用群集解析自定义标记图标 - How can i parse a custom marker icon with clustering in iOS Swift 当我在iOS中点击google上的标记时,如何使用两个按钮显示叠加信息视图 - How to show overlay info view with two button more when i click a marker on google in iOS 我可以使用 iOS 图表显示所有标记吗? - Can I show all the markers using iOS charts? ios图表:是否可以在标记中显示更多值 - ios-charts: Is it possible to show more values in marker 如何在MFMailcomposer视图中显示默认导航栏,而不是在iOS中显示自定义导航栏 - How to show the default navigation bar in MFMailcomposer view rather than custom nav bar in ios 如何在iOS的驾驶模式下在Google地图上删除以前的自定义标记 - How can i remove previous custom marker on Google Maps while Driving mode in iOS 如何在iOS Swift中使用标记集群设置自定义标记图标 - how can I set custom marker icon with markers cluster in iOS Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM