How do you draw vertical line using coreplot CPPlo

2019-06-14 01:54发布

问题:

How do I draw a vertical line on plotSymbol using Custom PlotSymbol? If it would be grateful, give any samples regarding that.

Sri

回答1:

You simply create a CGPath that describes the outline of your custom symbol. Here's a sample from CPTestApp (in the CorePlot/examples folder):

CPPlotSymbol *symbol = [[[CPPlotSymbol alloc] init] autorelease];
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0., 0.);

CGPathAddEllipseInRect(path, NULL, CGRectMake(0., 0., 10., 10.));
CGPathAddEllipseInRect(path, NULL, CGRectMake(1.5, 4., 3., 3.));
CGPathAddEllipseInRect(path, NULL, CGRectMake(5.5, 4., 3., 3.));
CGPathMoveToPoint(path, NULL, 5., 2.);
CGPathAddArc(path, NULL, 5., 3.3, 2.8, 0., pi, TRUE);
CGPathCloseSubpath(path);

symbol.customSymbolPath = path;
symbol.usesEvenOddClipRule = YES;
CGPathRelease(path);

You can set the plotSymbol property on the scatter plot to apply your symbol to every point or use the -symbolForScatterPlot:recordIndex: or -symbolsForScatterPlot:recordIndexRange: datasource method to apply it to some of the points.