问题描述
我已经搜索并搜索了如何在用户单击条形图中的条形图时使用 Swift 的 Charts(是 iOS 图表)显示 MarkerView.
I have searched and searched for how to display the MarkerView when the user clicks on a bar in a bar chart using Charts (was iOS-charts) for Swift.
文档说明该库能够使用 MarkerViews突出显示值(使用可自定义的弹出视图)",但我不知道如何显示.
The documentation states the library is capable of "Highlighting values (with customizable popup-views)" using MarkerViews, but I don't know how to show one.
我想要在用户点击条形图中的条形时显示一个小工具提示,如下图所示.
I want a little tool tip to display, like the image below, when the user clicks on a bar in the bar chart.
条形图上的工具提示:
我已准备好 chartValueSelected 函数,该函数会在选择条形时触发.
I have the chartValueSelected function ready which fires when a bar is selected.
推荐答案
所以你正在使用 Charts 对?
So you are using Charts right?
你检查 BallonMarker.swift 了吗?
Did you check BallonMarker.swift?
/ChartsDemo/Classes/Components/BallonMarker.swift
迅捷
let marker:BalloonMarker = BalloonMarker(color: UIColor.redColor(), font: UIFont(name: "Helvetica", size: 12)!, insets: UIEdgeInsets(top: 7.0, left: 7.0, bottom: 7.0, right: 7.0))
marker.minimumSize = CGSizeMake(75.0, 35.0)
chartView.marker = marker
Swift 3 更新
let marker:BalloonMarker = BalloonMarker(color: UIColor.black, font: UIFont(name: "Helvetica", size: 12)!, textColor: UIColor.white, insets: UIEdgeInsets(top: 7.0, left: 7.0, bottom: 7.0, right: 7.0))
marker.minimumSize = CGSize(width: 75.0, height: 35.0)
chartView.marker = marker
目标 C
BalloonMarker *marker = [[BalloonMarker alloc] initWithColor:[UIColor colorWithRed:14.0/255.0 alpha:1.0] font:[UIFont systemFontOfSize:12.0] insets: UIEdgeInsetsMake(7.0, 7.0, 7.0, 7.0)];
marker.minimumSize = CGSizeMake(75.f, 35.f);
_chartView.marker = marker;
这篇关于当用户点击图表时创建一个 MarkerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!