0
votes

I have a data array with values:

[1,2,4,5,7..]

and after set auto labeling policy, it will auto draw data at each point. but there will be gap between 2 and 4, 5 and 7.

my question is how to remove this gap between each data and have a normal behavior when pinch or scale the graph, also the position of data "4" with show 4 at x axis, data "2" will show 2 at x axis.

Another problem I met is that, when I drag with in the graph, the axis segment sometimes will disappear or total axis will disappear.

(I cannot upload image, there is a copy of that in

https://github.com/core-plot/core-plot/issues/113

Thanks in advance. here is my graph setup code:

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

when I pinch or scale the graph, I will set the plot range dynamic according to the postion shown in current view port.

What I need is a sooth change when scale or pinch, and fixed major grid position. How can I implement that effect?

1
Please post your graph setup code to help troubleshoot the axis line issue. - Eric Skroch
What do you mean by "normal behavior" with the pinch gesture? - Eric Skroch

1 Answers

0
votes

The bars for a trading range plot are drawn at the x-value provided by the datasource. If you want a bar at x=3, make sure the datasource provides one. Remember that the x-value is independent of the data index.