I am constructing an application that plots a barchart.
when i wrote this line
num=(NSDecimalNumber *)[NSDecimalNumber numberWithInt:index];
return num;
in the method
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
it works properly
but i need to pass a float number to plot
for that i wrote
num=(NSDecimalNumber *)[NSDecimalNumber numberWithFloat:f1];
return num;
then all of the bars appears together
i tried to adjust the barofset and barwidth but no solution
can anyone help me
thanks in advance
Assuming these numbers are for the CPTBarPlotFieldBarLocation field, you need to check the corresponding plot space range (xRange for vertical bars and yRange for horizontal). Make sure the location and length of the plot space range are appropriate for the range of numbers you're returning for this field. It sounds like the length is too large.
Related
I already have an chart like this Chart 1
The day 9/28 and 9/30 plot are displayed continuously. I want to display 9/29 plot with no data, and expect the red line go from 9/28 to 9/30.
So I add 9/29 plot, with x = 9/29 and return value nil for 9/29 in this fuction
- (NSNumber *)numberForPlot:(CPTPlot *)plot
field:(NSUInteger)fieldEnum
recordIndex:(NSUInteger)index
But no line shows up, like this: Chart 2
Is there any way to achieve the chart I want? Thanks
Don't return values for the dates you want to skip. For the second chart, it only shows three data points (9/28, 9/30, and 10/3). Return three (3) from -numberOfRecordsForPlot: and only return data values for those dates.
I have one graph correctly plotted in my plotspace and I am trying to plot a second graph triggered by a segmented control button instead of the first one. The x-axis (xRange and globalXRange) and their corresponding values between graph 1 and 2 are staying the same, just the corresponding y-axis (scale and labels) are changing. This requires a scale and label change on the y-axis...
For the first plot I already set:
// PLOT RANGE Y-Axis
self.plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(-1.2) length:CPTDecimalFromDouble(6.5)];
self.plotSpace.globalYRange = self.plotSpace.yRange;
// Visibility of Y-Axis
self.axisSet.yAxis.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(0)
length:CPTDecimalFromInteger(5)];
This is working perfect.
When changing self.plotSpace.yRange and self.plotSpace.grobalYRange with new CPTPlotRanges ( I am doing this in the same way as above inside of my segment - if-else statement) , both: y-axis scales and labels are not changing as desired, w.r.t the new y-axis ranges (should be from 0 - 100 and not still from 0 - 5). Just the minorTicksPerInterval changes properly.
How to do that? BTW: I am not looking for 2 y-axis in the same plot. Any suggestions...
The globalYRange constrains the new values assigned to the yRange. Set globalYRange to nil before changing the yRange.
self.plotSpace.globalYRange = nil;
self.plotSpace.yRange = newRange;
self.plotSpace.globalYRange = self.plotSpace.yRange;
I have a simple core plot with xAxis alternatingBandFills
xAxis.alternatingBandFills = [NSArray arrayWithObjects:[bandFillColor colorWithAlphaComponent:0.1], [NSNull null], nil];
The effect:
Now when I scroll horizontally (panning to the left), when the region of x between 0 and 10 goes to the left outside of the viewable range, the fill color would "jump" and 10 to 20 would become highlighted instead (and 20 to 30 would become white, and so on).
Is there a way to keep the band as it is without the alternation while scrolling?
For now, use a plot space delegate to monitor changes to the plot space and shuffle the fill colors as needed. I added issue 601 to the Core Plot issue tracker requesting a feature to make this easier.
As a workaround, I implemented some BarPlot on the visible screen but the performance are bad on iPhone 4&4S compare to alternatingBandFills even with very few data so I came back to this alternatingBandFills by shuffling the array in the - plotSpace:didChangePlotRangeForCoordinate: has Eric said. Here the solution I implemented:
-(void)plotSpace:(CPTPlotSpace *)space didChangePlotRangeForCoordinate:(CPTCoordinate)coordinate {
if (self.plotSpace.xRange.locationDouble <0) {//area before your xrange origin to pass from 0 to -1 and not 0 to -0
value = value-1;
}
int value = plotSpace.xRange.locationDouble.x/majorInterval;
if (self.currentFillBand != value%2) {
NSArray * array = xaxis.alternatingBandFills;
xaxis.alternatingBandFills = #[array[1], array[0]];
self.currentFillBand = value%2;
}
}
If your globalXRange is larger/before than your xrange.origin, so your xRange.location will be <0 when you scroll backward but the value variable will pass from 0 to -0 and so I retrieve -1 to the value in such case.
Note: I still have a small issue with a new majorTick before your globalXRange, I got a shuffling I can't fix, so I avoid that case.
I'm using Coreplot and I need help plotting data on a graph.
I've populated an array called results with dictionary data. Output of it's contents are as follows (I've shortened data for simplicity purposes) -
{
temperature = "5.0832667,5.2916833,4.6418246";
windspeed = "2.333,2.521,2.021,1.833,1.292,1.167";
}
I'm having trouble getting this data to plot using the method numberForPlot. Here is what I've done up until now. Below is an attempt to only plot the 'temperature' data -
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index;
return [results valueForKey:#"temperature"];
{
I'm guessing it's to do with the way I create my dictionary, as they are strings, and NSNumbers are needed? As an additional note, here is the code that created the dictionary -
for(counter = 0; counter < [node childCount]; counter++) {
[item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] name]];
}
[results addObject:item];
Any help would be greatly appreciated as I've been trying to get this working for several days now! Thanks
Each plot type uses different "fields" to request the plot data. For example, a scatterplot uses CPTScatterPlotFieldX to request x-values and CPTScatterPlotFieldY to request y-values.
The -numberOfRecordsForPlot: method tells Core Plot how many data points are available for the plot. The -numberForPlot:field:recordIndex: method will be called once with each field value for each index in the range 0 through (n - 1).
There are a lot of example apps included with Core Plot. Look at any of them to see how to set up the datasource.
I wanted to get the axisLabel value by clicking on it to plot a line graph? How can achieve this? Is there any possibilities to select each label value?. I have tried plot space delegate method of -(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceDownEvent:(id)event atPoint:(CGPoint)point.By this i can able get bound values only. what would be the best solution?
Thanks in advance.
Convert the point from the coordinate system of the graph layer to the plot area:
CGPoint pointInPlotArea = [space.graph convertPoint:interactionPoint
toLayer:space.graph.plotAreaFrame.plotArea];
Convert the point to data coordinates:
NSDecimal plotPoint[2];
[space plotPoint:plotPoint forPlotAreaViewPoint:pointInPlotArea];
or
double plotPoint[2];
[space doublePrecisionPlotPoint:plotPoint forPlotAreaViewPoint:pointInPlotArea];