CorePlot 2.0传奇

时间:2016-03-25 16:53:53

标签: core-plot

我已经在我的mac应用程序中安装了CorePlot 2.0,并且我已经为我的CPTXYGraph对象添加了CPTLegend,但是从未调用过legendTitleForPieChart方法。如何为每个绘图指定图例标题?

显然,我已经删除了此档案中的大部分其他代码。

import Cocoa
import CorePlot

class ReportYearProducerProductionViewController: NSViewController {
    @IBOutlet private weak var hostingView: CPTGraphHostingView!

    private func configureChart() {
        let pieChart = CPTPieChart()
        pieChart.dataSource = self

        hostingView.hostedGraph!.addPlot(pieChart)
    }
}

extension ReportYearProducerProductionViewController: CPTPieChartDataSource {
    func legendTitleForPieChart(pieChart: CPTPieChart, recordIndex idx: UInt) -> String? {
        return "Title \(idx)"
    }
}

1 个答案:

答案 0 :(得分:0)

您在图表有任何图表之前创建了图例。由于没有与图例关联的图表,因此无法向图表询问标题。

在将图表添加到图表后创建图例(CPTLegend(graph: graph)),或者在创建图表和图例时将图表添加到图表中。