CorePlot:如何设置触摸事件,当用户点击图表上的CandleStick时,那么它可以显示蜡烛X和Y值? [英] CorePlot: how to set touch event, when user click the CandleStick on the chart, then it can show the Candle X and Y Value?

查看:252
本文介绍了CorePlot:如何设置触摸事件,当用户点击图表上的CandleStick时,那么它可以显示蜡烛X和Y值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CorePlot:如何设置触摸事件,当用户单击图表上的CandleStick时,那么它可以显示蜡烛X和Y值?

CorePlot: how to set touch event, when user click the CandleStick on the chart, then it can show the Candle X and Y Value?

边不正确,因为图表可以放大和缩小
,所以可能需要包括值的值。
但是我不知道缩放值....

The value in left side is not correct,because the chart can be zoom in and zoom out , so may be the value need to include the scale value. But i don't know the scale value....

所以有任何方法来获得CandleStick图表通过单击屏幕?

so is there any way to get the CandleStick Chart By click the screen?

graph = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
CPTTheme *theme = [CPTTheme themeNamed:kCPTStocksTheme];
[graph applyTheme:theme];

graph.frame = self.view.bounds;

graph.paddingLeft = 20.0; 
graph.paddingTop = 20.0; 
graph.paddingRight = 40.0; 
graph.paddingBottom = 60.0;

[graphHost setAllowPinchScaling:YES];

graph.plotAreaFrame.masksToBorder = NO;
graph.plotAreaFrame.cornerRadius = 0.0f;
CPTMutableLineStyle *borderLineStyle = [CPTMutableLineStyle lineStyle];
borderLineStyle.lineColor = [CPTColor blackColor];
borderLineStyle.lineWidth = 2.0f;
graph.plotAreaFrame.borderLineStyle = borderLineStyle;
self.graphHost.hostedGraph = graph;

// Axes
CPTXYAxisSet *xyAxisSet = (id)graph.axisSet;

CPTXYAxis *xAxis = xyAxisSet.xAxis;
CPTMutableLineStyle *lineStyle = [xAxis.axisLineStyle mutableCopy];
lineStyle.lineCap = kCGLineCapButt;
xAxis.axisLineStyle = lineStyle;

[lineStyle release];
xAxis.labelingPolicy = CPTAxisLabelingPolicyAutomatic;


xAxis.isFloatingAxis=YES;
xAxis.minorTicksPerInterval = 4;
xAxis.preferredNumberOfMajorTicks = 9;
xAxis.orthogonalCoordinateDecimal=CPTDecimalFromString(@"110");




CPTXYAxis *yAxis = xyAxisSet.yAxis;


yAxis.isFloatingAxis=YES;
yAxis.labelingPolicy = CPTAxisLabelingPolicyAutomatic;

CPTConstraints yConstraints = {CPTConstraintNone, CPTConstraintFixed};
yAxis.constraints = yConstraints;


CPTScatterPlot *dataSourceLinePlot = [[[CPTScatterPlot alloc] initWithFrame:graph.bounds] autorelease];
dataSourceLinePlot.delegate=self;
dataSourceLinePlot.identifier = @"Data Source Plot";
dataSourceLinePlot.dataLineStyle = nil;
dataSourceLinePlot.dataSource = self;
[graph addPlot:dataSourceLinePlot];

CPTColor *areaColor = [CPTColor clearColor];
CPTGradient *areaGradient = [CPTGradient gradientWithBeginningColor:areaColor endingColor:[CPTColor clearColor]];
areaGradient.angle = -90.0f;
CPTFill *areaGradientFill = [CPTFill fillWithGradient:areaGradient];
dataSourceLinePlot.areaFill = areaGradientFill;
dataSourceLinePlot.areaBaseValue = CPTDecimalFromDouble(200.0);

areaColor = [CPTColor colorWithComponentRed:0.0 green:1.0 blue:0.0 alpha:0.6];

areaGradient = [CPTGradient gradientWithBeginningColor:[CPTColor clearColor] endingColor:areaColor];
areaGradient.angle = -90.0f;
areaGradientFill = [CPTFill fillWithGradient:areaGradient];
dataSourceLinePlot.areaFill2 = areaGradientFill;
dataSourceLinePlot.areaBaseValue2 = CPTDecimalFromDouble(200.0);

// OHLC plot
CPTMutableLineStyle *whiteLineStyle = [CPTMutableLineStyle lineStyle];
whiteLineStyle.lineColor = [CPTColor blackColor];
whiteLineStyle.lineWidth = 1.0f;

CPTTradingRangePlot *ohlcPlot = [[[CPTTradingRangePlot alloc] initWithFrame:graph.bounds] autorelease];
ohlcPlot.identifier = @"OHLC";
ohlcPlot.lineStyle = whiteLineStyle;
CPTMutableTextStyle *whiteTextStyle = [CPTMutableTextStyle textStyle];
whiteTextStyle.color = [CPTColor whiteColor];
whiteTextStyle.fontSize = 11.0;
ohlcPlot.labelTextStyle = whiteTextStyle;
ohlcPlot.labelOffset = 30.0;
ohlcPlot.stickLength = 12.0f;
ohlcPlot.dataSource = self;
//ohlcPlot.plotStyle = CPTTradingRangePlotStyleOHLC;
ohlcPlot.plotStyle = CPTTradingRangePlotStyleCandleStick;

ohlcPlot.increaseFill = [(CPTFill *)[CPTFill alloc] initWithColor:[CPTColor greenColor]];
ohlcPlot.decreaseFill = [(CPTFill *)[CPTFill alloc] initWithColor:[CPTColor redColor]];

[graph addPlot:ohlcPlot];

// Add plot space for horizontal bar charts
CPTXYPlotSpace *volumePlotSpace= [[CPTXYPlotSpace alloc] init];


volumePlotSpace.delegate=self;
volumePlotSpace.globalXRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(30.0f)];
volumePlotSpace.globalYRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(800.0f) length:CPTDecimalFromFloat(100.0f)];
volumePlotSpace.allowsUserInteraction=TRUE;    

volumePlotSpace.allowsUserInteraction=YES;

volumePlotSpace.identifier = @"Volume Plot Space";
[graph addPlotSpace:volumePlotSpace];
[volumePlotSpace release];

// Data puller
NSDate *start = [NSDate dateWithTimeIntervalSinceNow:-60.0 * 60.0 * 24.0 * 7.0 * 12.0]; // 12 weeks ago
NSDate *end = [NSDate date];
APYahooDataPuller *dp = [[APYahooDataPuller alloc] initWithTargetSymbol:@"AAPL" targetStartDate:start targetEndDate:end];
[self setDatapuller:dp];
[dp setDelegate:self];
[dp release];

推荐答案

你可以继承CPTTradingRangePlot并自己实现触摸处理。看看CPTBarPlot和CPTScatterPlot有关如何做的想法。

This is not natively supported yet in Core Plot. You could subclass CPTTradingRangePlot and implement the touch handling yourself. Look at CPTBarPlot and CPTScatterPlot for ideas on how to do it.

这篇关于CorePlot:如何设置触摸事件,当用户点击图表上的CandleStick时,那么它可以显示蜡烛X和Y值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆