我有一个值为的数据数组:
[1,2,4,5,7 ..]
在设置自动标记策略后,它将自动在每个点绘制数据。 但是在2和4,5和7之间会有差距。
我的问题是如何消除每个数据之间的这种差距,并且在捏合或缩放图形时具有正常行为,数据“4”的位置在x轴处显示4,数据“2”将在x处显示2轴。
我遇到的另一个问题是,当我在图表中拖动时,轴段有时会消失或总轴会消失。
(我无法上传图片,
中有副本https://github.com/core-plot/core-plot/issues/113
提前致谢。 这是我的图表设置代码:
_graph = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
CPTTheme * theme = [CPTTheme themeNamed:kCPTPlainWhiteTheme];
[_graph applyTheme:theme];
[_graph setCornerRadius:0.0f];
//
_graphHost = [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 0, hostView.width, hostView.height)];
[_graphHost setBackgroundColor:[UIColor whiteColor]];
_dynamicPrice = [[UILabel alloc] initWithFrame:CGRectMake(10, _graphHost.height/2, 35, 10) font:[UIFont systemFontOfSize:8.0] color:[UIColor blueColor] text:@"test"];
[_dynamicPrice setBackgroundColor:[UIColor grayColor]];
[_dynamicPrice setTextAlignment:NSTextAlignmentCenter];
_dynamicPrice.layer.transform = CATransform3DMakeRotation(M_PI, 1, 0, 0);
_graphHost.hostedGraph = _graph;
[_graphHost addSubview:_dynamicPrice];
[hostView addSubview:_graphHost];
CPTMutableLineStyle *borderLineStyle = [CPTMutableLineStyle lineStyle];
borderLineStyle.lineColor = [CPTColor whiteColor];
borderLineStyle.lineWidth = 0.1f;
_graph.plotAreaFrame.borderLineStyle = nil;
_graph.plotAreaFrame.paddingTop += 10.0;
_graph.plotAreaFrame.paddingRight += 10.0;
_graph.plotAreaFrame.paddingBottom += 10.0;
_graph.plotAreaFrame.paddingLeft += 25.0;
_graph.plotAreaFrame.masksToBorder = NO;
_graph.plotAreaFrame.plotArea.delegate = self;
//
CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle];
majorGridLineStyle.lineWidth = 0.3f;
majorGridLineStyle.lineColor = [[CPTColor colorWithGenericGray:0.2] colorWithAlphaComponent:0.75];
//
CPTMutableLineStyle *minorGridLineStyle = [CPTMutableLineStyle lineStyle];
minorGridLineStyle.lineWidth = 0.1f;
minorGridLineStyle.lineColor = [[CPTColor lightGrayColor] colorWithAlphaComponent:0.1];
UIFont *labelFont = [UIFont systemFontOfSize:8.0f];
CPTTextStyle *labelStyle = [CPTTextStyle textStyleWithAttributes:@{NSFontAttributeName:labelFont, NSForegroundColorAttributeName:[UIColor blueColor]}];
// NSBackgroundColorAttributeName:[UIColor grayColor]
// Axes
CPTXYAxisSet *xyAxisSet = (id)_graph.axisSet;
CPTXYAxis *x = xyAxisSet.xAxis;
x.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
x.majorIntervalLength = CPTDecimalFromDouble(60*3);
x.minorTicksPerInterval = 0;
x.majorGridLineStyle = majorGridLineStyle;
x.minorGridLineStyle = minorGridLineStyle;
x.axisConstraints = [CPTConstraints constraintWithRelativeOffset:0.0];
x.labelTextStyle = labelStyle;
//x.minorTickLabelTextStyle = labelStyle;
[self setXLabelDateFormater:_currentKLineType];
CPTXYAxis *y = xyAxisSet.yAxis;
y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y.orthogonalCoordinateDecimal = CPTDecimalFromDouble(20);
y.majorIntervalLength = CPTDecimalFromDouble(20);
y.minorTicksPerInterval = 0;
y.majorGridLineStyle = majorGridLineStyle;
y.minorGridLineStyle = minorGridLineStyle;
y.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
y.labelOffset = 0.0;
y.labelTextStyle = labelStyle;
y.labelFormatter = yFormater;
// OHLC plot
CPTMutableLineStyle *redLineStyle = [CPTMutableLineStyle lineStyle];
redLineStyle.lineColor = [CPTColor redColor];
redLineStyle.lineWidth = 1.0f;
CPTMutableLineStyle *greenLineStyle = [CPTMutableLineStyle lineStyle];
greenLineStyle.lineColor = [CPTColor greenColor];
greenLineStyle.lineWidth = 1.0f;
CPTTradingRangePlot *kLineChart= [[CPTTradingRangePlot alloc] initWithFrame:_graph.bounds];
kLineChart.identifier = PLOT_KLINE;
kLineChart.lineStyle = redLineStyle;
CPTMutableTextStyle *whiteTextStyle = [CPTMutableTextStyle textStyle];
whiteTextStyle.color = [CPTColor whiteColor];
whiteTextStyle.fontSize = 12.0;
kLineChart.labelOffset = 0.0;
kLineChart.barCornerRadius = 0.0;
kLineChart.barWidth = 15.0;
kLineChart.increaseFill = [CPTFill fillWithColor:[CPTColor redColor]];
kLineChart.decreaseFill = [CPTFill fillWithColor:[CPTColor greenColor]];
kLineChart.increaseLineStyle = redLineStyle;
kLineChart.decreaseLineStyle = greenLineStyle;
kLineChart.dataSource = self;
kLineChart.delegate = self;
kLineChart.plotStyle = CPTTradingRangePlotStyleCandleStick;
[_graph addPlot:kLineChart];
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)_graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(-0.5) length:CPTDecimalFromDouble(oneDay * _kLineDataItems.count)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(0) length:CPTDecimalFromInteger(4)];
plotSpace.allowsUserInteraction = YES;
plotSpace.delegate = self;
[plotSpace scaleToFitPlots:[_graph allPlots]];
当我捏合或缩放图形时,我会根据当前视图端口中显示的位置设置动态绘图范围。
我需要的是在缩放或捏合时的固定变化,以及固定的主要网格位置。 我该如何实现这种效果?
答案 0 :(得分:0)
交易范围图的柱形图是以数据源提供的x值绘制的。如果你想要一个x = 3的条,请确保数据源提供一个。请记住,x值与数据索引无关。