gpt4 book ai didi

iphone - CorePlot : how to set touch event, 当用户单击图表上的 CandleStick 时,它可以显示蜡烛 X 和 Y 值吗?

转载 作者:行者123 更新时间:2023-12-03 21:18:23 25 4
gpt4 key购买 nike

CorePlot:如何设置触摸事件,当用户点击图表上的CandleStick时,可以显示Candle X和Y值?

左侧的值不正确,因为图表可以放大和缩小,因此该值可能需要包含比例值。但我不知道比例值......

有什么方法可以通过点击屏幕来获取 CandleStick 图表吗?

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];

enter image description here

最佳答案

Core Plot 本身尚不支持此功能。您可以子类化 CPTradingRangePlot 并自行实现触摸处理。查看 CPTBarPlot 和 CPTScatterPlot 了解如何执行此操作的想法。

关于iphone - CorePlot : how to set touch event, 当用户单击图表上的 CandleStick 时,它可以显示蜡烛 X 和 Y 值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7872416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com