【发布时间】:2016-10-11 12:57:56
【问题描述】:
我使用 Core Plot 文件来创建我的图表。 但 CorePlot 不包含事件“点击图例项”。
如何检测用户对图例项的点击?
class ViewController: NSViewController, CPTPlotDataSource, CPTPieChartDataSource {
@IBOutlet weak var graphView: CPTGraphHostingView!
override func viewDidLoad() {
super.viewDidLoad()
let graph = CPTXYGraph(frame: CGRect.zero)
var axes = graph.axisSet as! CPTXYAxisSet
var lineStyle = CPTMutableLineStyle()
lineStyle.lineWidth = 0
axes.xAxis?.axisLineStyle = lineStyle
axes.yAxis?.axisLineStyle = lineStyle
var pie = CPTPieChart()
pie.pieRadius = 100
pie.dataSource = self
pie.centerAnchor = CGPoint(x: 0.18, y: 0.75)
graph.add(pie)
var theLegend=CPTLegend(graph: graph)
var legendFill=CPTFill(color: CPTColor.gray())
theLegend.fill = legendFill
var legendLineStyle = CPTMutableLineStyle()
legendLineStyle.lineColor = CPTColor.white()
theLegend.borderLineStyle = legendLineStyle
theLegend.cornerRadius = 2.0
theLegend.frame = CGRect(x: 0, y: 0, width: 0.1, height: 50)
theLegend.numberOfColumns = 1
graph.legend = theLegend
graph.legendDisplacement = CGPoint(x: 0.5, y: 300)
self.graphView.hostedGraph = graph
}
【问题讨论】:
标签: swift macos core-plot legend clickable