I'm trying to draw a candlesitck chart.
But when I scale it to 0.5,the next candlestick will cover the former. Are there some methods can set the candlesticks' width or interval?
Another question, when I drag or scale the chart, I need to refresh the price label and candlesticks to let candlesticks in the screen can fill the YAsix's max and min.
How can I do that?
Thanks a lot.
Hi,
I'm not able to reproduce the overlap you're seeing. Are you setting the zoom scale programmatically, or just zooming in with a gesture? The width of the column is determined by the number of data points and the size of the chart and isn't controllable. Can you provide some sample code and a screenshot?For your second question, it sounds like you're trying to restrict zooming to horizontal zooming only, which you can do by setting
_chartView.zoomDisplayType = IGChartZoomHorizontal;
For the first question, when I zooming it , the chart shows like the image:
The candlestick will covered by one beside it. Howto fix this problem?
For my second question:
At first, the max price is 12850 and min is 12800.
After scaling it like this:
I need to set the max price to 12810 and min to 12800.
Howto do that automatic?
I'm afraid I don't see any images in the above post.
You can either include image links in your post if you're hosting the images elsewhere,or you can upload your image or a zip file by going to Options and clicking 'Add/Update' button
This is the oringinal chart:
Thanks,Rivlin. I have tested your sample.
But when I set createChartData mothod to create 200 object, the problem happened again.
When using chart's addSeriesForType method to create axes and series, the type of X axis depends on how you defined your datasource helper. Your axis will either be IGCategoryXAxis or IGCategoryDateTimeXAxis. FinancialPriceSeries only supports IGCategoryXAxis. Looks like you're casting your x axis to IGNumericXAxis, which financial series doesn't support. I'm attaching a small sample project that creates a candlestick chart, in which there's no overlap on zooming.
Apreciate your help.
For the first question, I haven't use IGCategoryDateTimeXAxis. I defined it like:
IGFinancialPriceSeries *financialPriceSeries = (IGFinancialPriceSeries *)[infraChart addSeriesForType:[IGFinancialPriceSeries class] usingKey:@"financialPriceCandlestickSeries" withDataSource:source firstAxisKey:@"xAxis" secondAxisKey:@"yAxis"]; IGNumericXAxis *x = [infraChart findAxisByKey:@"xAxis"]; CGFloat interval = (x.visibleMaximumValue - x.visibleMinimumValue) / 5; x.interval = interval;
The labels look well, but the candlesticks in chart are overlaping their former one.
The next part of below image is obvious.
The second question was solved, consulted your code:
IGCategoryXAxis *xAxis = [infraChart findAxisByKey:@"xAxis"]; IGNumericYAxis *yAxis = [infraChart findAxisByKey:@"yAxis"]; IGSeries *series = [infraChart findSeriesByKey:@"financialPriceCandlestickSeries"]; NSInteger minIndex = (NSInteger)xAxis.visibleMinimumValue; NSInteger maxIndex = (NSInteger)xAxis.visibleMaximumValue; if (maxIndex >= currentTotalItems) maxIndex = currentTotalItems -1; if (minIndex < 0) minIndex = 0;
CGFloat min = CGFLOAT_MAX; CGFloat max = CGFLOAT_MIN; for (int i = minIndex; i { IGOHLCPoint *pt = series.dataPoints[i]; min = MIN(min, pt.lowValue); max = MAX(max, pt.highValue); } yAxis.maximum = max; yAxis.minimum = min;
Are you using IGCategoryDateTimeXAxis in your chart? I think that's causing the overlap. The time axis should be used only in cases when you want to display values on the X axis at a non-constant interval. For example, if the distance between pt.A and pt.B is 10 seconds and the distance between pt.B and pt.C is 15 seconds. If you want even spacing between all your points, you should use IGCategoryXAxis instead of IGCategoryDateTimeXAxis. You can still display dates, you'll just have to use strings. There's a sample in NucliOS samples browser you can take a look at for an example of a candlestick series (it's under Chart samples -> Financial Price Series).
For your second question, the type of snapping you're describing isn't available in the chart view. I think you can work around this if you calculate the zoom scale and offset manually.Try something like this:
IGCategoryXAxis *xAxis = [_chartView findAxisByKey:@"x"]; IGNumericYAxis *yAxis = [_chartView findAxisByKey:@"y"]; IGSeries *series = [_chartView findSeriesByKey:@"series"];
NSInteger minIndex = (NSInteger)xAxis.visibleMinimumValue; NSInteger maxIndex = (NSInteger)xAxis.visibleMaximumValue; CGFloat min = CGFLOAT_MAX; CGFloat max = CGFLOAT_MIN;
for (int i=minIndex; i<maxIndex; i++) { IGOHLCPoint *pt = series.dataPoints[i]; min = MIN(min, pt.highValue); max = MAX(max, pt.lowValue); }
double scale = (yAxis.actualMaximumValue - yAxis.actualMinimumValue) / (max - min); double offset = _chartView.plotAreaRect.size.height * (scale / (yAxis.actualMaximumValue / max) - 1); _chartView.zoomScale = scale; _chartView.zoomContentOffset = CGPointMake(_chartView.zoomContentOffset.x, offset);
This would essentially go through all visible data points, calculate min and max values based on high and low values and calculate the zoom.