如何使用 iphone sdk 中的核心绘图库包装添加到绘图中的文本
我已经像这样向饼图添加了标签 -(CPTLayer *)dataLabelForPlot:(CPTPlot *)绘图记录索引:(NSUInteger)索引 {
CPTTextLayer *newLayer = nil;
UIFont *theFont;
static CPTMutableTextStyle *whiteText = nil;
if ( !whiteText )
{
whiteText = [[CPTMutableTextStyle alloc] init];
whiteText.color = [CPTColor blackColor];
whiteText.textAlignment = CPTTextAlignmentCenter;
whiteText.fontName = @"Helvetica-Bold";
whiteText.fontSize = 10.0f;
theFont = [UIFont fontWithName:whiteText.fontName size:whiteText.fontSize];
}
if ( [plot isKindOfClass:[CPTPieChart class]] )
{
newLayer.delegate = self;
newLayer = [[[CPTTextLayer alloc] initWithText:[NSString stringWithFormat:@"%@", [pieChartData2 objectAtIndex:index]] style:whiteText] autorelease];
}
return newLayer;
}
我想要的是 (1)我想将太长的文本换行。 (2) 我想显示切片标题及其值。 (3) 我需要在 title 和 Slice 上画一条线。 请任何人帮助我。
提前致谢
I had added labels to the pie chart like this
-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index
{
CPTTextLayer *newLayer = nil;
UIFont *theFont;
static CPTMutableTextStyle *whiteText = nil;
if ( !whiteText )
{
whiteText = [[CPTMutableTextStyle alloc] init];
whiteText.color = [CPTColor blackColor];
whiteText.textAlignment = CPTTextAlignmentCenter;
whiteText.fontName = @"Helvetica-Bold";
whiteText.fontSize = 10.0f;
theFont = [UIFont fontWithName:whiteText.fontName size:whiteText.fontSize];
}
if ( [plot isKindOfClass:[CPTPieChart class]] )
{
newLayer.delegate = self;
newLayer = [[[CPTTextLayer alloc] initWithText:[NSString stringWithFormat:@"%@", [pieChartData2 objectAtIndex:index]] style:whiteText] autorelease];
}
return newLayer;
}
What I want here is
(1)I want to wrap the text which is too long.
(2) I want to display the the Slice title and and its value .
(3) I need to draw a line to title and Slice .
Please any one help me.
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在文本中插入换行符 ('\n') 以换行到下一行。 Core Plot 不会自动换行任何文本。
这是一个数据源方法 - 它应该能够访问数据值和标题。使用两者来构建标签字符串。
尚不支持在标签上绘制线条。您可以创建 CPTTextLayer 的自定义子类,除了文本之外还绘制线条,并使用它代替库存 CPTTextLayer 来制作标签。
You can insert newline characters ('\n') in the text to wrap to the next line. Core Plot does not auto-wrap any text.
This is a datasource method—it should have access to the data values and the title. Use both to build the label string.
Drawing lines to a label is not supported yet. You could make a custom subclass of CPTTextLayer that draws the line in addition to the text and use that instead of the stock CPTTextLayer to make the labels.