【问题标题】:How to change the Legend titles in core-plot stacked bar chart?如何更改核心图堆积条形图中的图例标题?
【发布时间】:2015-11-24 09:03:10
【问题描述】:

How to show bar values on CorePlot -Stacked bar chart

在这篇文章之后,我想更改堆叠条形图的图例标题值,默认情况下它采用代码中给出的“集合”值。 我无法更改“sets”值,因为我使用它来匹配并从 Web 服务获取值。

上图不是“D”、“O”、“P”,我需要给出全名的含义。 我尝试了coloredBarChart中给出的这样的代码,

-(NSString *)legendTitleForBarPlot:(CPTBarPlot *)barPlot recordIndex:(NSUInteger)index

{
    return [NSString stringWithFormat:@"Bar %lu", (unsigned long)(index + 1)];
}

然后它看起来像下面,它获取图表中所有堆叠条的索引值。

如何更改 core-plot 中的图例标题值?

【问题讨论】:

    标签: ios charts core-plot legend


    【解决方案1】:

    设置每个绘图的title 属性以更改图例中显示的标签。如果您想在标签中显示带样式的文本,可以改用attributedTitle

    【讨论】:

    • 嗨,我试过了,-(NSString *)legendTitleForBarPlot:(CPTBarPlot *)barPlot recordIndex:(NSUInteger)index { if ([barPlot.identifier isEqual:[sets objectForKey:@"D" ]] == YES) { barPlot.title=@"A"; } else if ([barPlot.identifier isEqual:[sets objectForKey:@"O"]] == YES) { barPlot.title=@"AA"; } else if ([barPlot.identifier isEqual:[sets objectForKey:@"P"]] == YES) { barPlot.title=@"AAA"; } 返回 barPlot.title; } 但它没有成功,我可以在哪里添加栏标题?
    • 我厌倦了这样的方法 "-(void)barPlot:(CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)index" if (plotIndex ==0) { plot.title=@"A "; }else if (plotIndex ==1) { plot.title=@"AA"; }else if (plotIndex ==2) { plot.title=@"AAA"; } 不起作用请告诉我如何解决此问题?
    • - (double)doubleForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {. NSInteger plotIndex = 0; if ([plot.identifier isEqual:[sets objectForKey:@"D"]] == YES) { plotIndex = 0; } else if ([plot.identifier isEqual:[sets objectForKey:@"O"]] == YES) { plotIndex = 1; } else if ([plot.identifier isEqual:[sets objectForKey:@"P"]] == YES) { plotIndex = 2; }if (plotIndex ==0){plot.title=@"A";}else if (plotIndex ==1){plot.title=@"AA";}else if (plotIndex ==2){ plot.title =@"AAA";} } 为所有 3 个图例值显示“A”
    • 我在哪里可以为每个情节设置标题,请提供一些参考。
    • 在初始设置期间在绘图上设置title。在将情节添加到图例之前的任何时间都可以使用。
    猜你喜欢
    • 2018-08-13
    • 1970-01-01
    • 1970-01-01
    • 2017-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    • 2017-05-27
    相关资源
    最近更新 更多