Search code examples
core-plot

CorePlot legend displays but no names are shown


When my bar chart displays I see an area for the legend as it's showing the little colored squares for each plot, but there's no text next to the colored square. I'm sure it's because I've done my method wrong. This is how I get the titles:

func legendTitleForBarPlot(barPlot: CPTBarPlot, recordIndex idx: UInt) -> String? {
    guard let ident = barPlot.identifier as? String else { return nil }
    guard alreadyPrintedLegend[ident] == nil else { return nil }

    alreadyPrintedLegend[ident] = true

    return ident
}

When my plots are created I set the identifier to the name of the plot that I want displayed. If I put some print statements above I do see each plot name being printed once.


Solution

  • Do not implement the delegate method and the legend will show properly.

    I put this as an answer so when people are searching they see this was resolved.