iPhone MIMChartLib Chart Drawing: How can i set the Y-axis starting from 18000 but not 0? - iphone

I am now using MIMChartLib to developer Iphone Chart,
But i am having trouble about the line chart,
for example
here is my CSV
Time;NAME;value001;value002;value003;value004;
01:00.0;ABCABC;1837;1837.2;1836.5;1831
02:00.0;ABCABC;1836.7;1837;1836.5;1836.7
03:00.0;ABCABC;1827;1827.2;1816.5;1826.9
04:00.0;ABCABC;1837;1837.2;1836.5;1836.9
05:00.0;ABCABC;1837;1837.2;1836.5;1836.9
How can i set the Y axis to be 18000, but not start from zero.
otherwise,the chart will show really really small.
here is preview:
here is my code
/*
Date;Time;Currency;Bid;Ask
14/9/2011;00:03.0;LLGUSD;1836.5;1837
*/
[MIMColor InitColors];
NSString *csvPath1 = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"myTableBar.csv"];
//LineGraph *lineGraph=[[LineGraph alloc]initWithFrame:CGRectMake(100, 20, 220, 380)];
LineGraph *lineGraph=[[LineGraph alloc]initWithFrame:Chartarea.frame];
lineGraph.needStyleSetter=YES;
lineGraph.xIsString=YES;
lineGraph.anchorType=CIRCLEBORDER; //OTHER anchorType
[lineGraph readFromCSV:csvPath1 titleAtColumn:1 valueInColumn:[NSArray arrayWithObjects:#"1",#"3", nil]];
[lineGraph displayYAxis];
[lineGraph displayXAxisWithStyle:5]; //OTHER styles FOR X-Axis Labels
[lineGraph drawWallGraph];
[self.view addSubview:lineGraph];
Thank you very much!!

go this link
https://github.com/ReetuRaj/MIMChart-Library
in YAxisBand.m file u have this method it work for me.....
-(void)setScaleForYTile:(float)value withNumOfLines:(int)numOfHorLines
{
pixelPerYTile=18000000.0;
//pixelPerYTile=value;
HorLines=numOfHorLines;
[self setNeedsDisplay];
}

go this link
https://github.com/ReetuRaj/MIMChart-Library
In MIMLineGraph.m
go to the function -(void)_findScaleForYTile
and REMOVE the following code
minOfY=[MIM_MathClass getMinFloatValue:[_yValElements objectAtIndex:0]];
for (int i=1; i<[_yValElements count]; i++)
{
float minOfY1=[MIM_MathClass getMinFloatValue:[_yValElements objectAtIndex:i]];
if(minOfY1<minOfY)
minOfY=minOfY1;
}
and set the value of minOfY directly as zero instead of doing the above calculation
minOfY = 18000000.0;
NOTE: in MIMChartLib minimum value plotted in yaxis will be the smallest value that you give in CSV file for plotting..so if u need to start yaxis from 18000000.0 then if the minimum value in your CSV file is the same then MIMCHART will automatically set the starting value of yaxis as 18000000.0

Related

How to debug missing dataset

I am working on a graph implementation for a health app and the user can choose which fields to graph.
There are some combination of fields which never appear on the graph.
From the debugging I have done so far I can see that the values for all the fields are created correctly.
So ultimately my question is, why is there no line for "Weight Moving Average"
But really I would like to know how to debug this problem. What be the recommended next step for getting to the bottom of it?
Code:
if (isMovingAverage) {
dataset.mode = LineChartModeCubicBezier;
dataset.cubicIntensity = 0.1;
dataset.lineWidth = 2;
dataset.highlightEnabled = NO;
[dataset setColor: baseColor];
dataset.fillAlpha = 1.f;
dataset.drawCirclesEnabled = NO;
NSArray *gradientColors = #[
(id)[UIColor whiteColor].CGColor,
(id)baseColor.CGColor
];
CGGradientRef gradient = CGGradientCreateWithColors(nil, (CFArrayRef)gradientColors, nil);
dataset.fillAlpha = 1.f;
dataset.fill = [ChartFill fillWithLinearGradient:gradient angle:90.f];
dataset.drawFilledEnabled = YES;
dataset.drawHorizontalHighlightIndicatorEnabled = NO;
CGGradientRelease(gradient);
NSLog(#"Dataset: %#", dataset);
}
Debug output:
Formatting: Weight Moving Avg
2017-07-28 17:06:49.425518+0100 BodyTrackItLite[5239:1893083] Using color: UIExtendedSRGBColorSpace 0.07 0.62 0.64 1
2017-07-28 17:06:49.426723+0100 BodyTrackItLite[5239:1893083] Dataset: Charts.LineChartDataSet, label: Weight Moving Average, 140 entries
Metaphox was right in his comment, one dataset was blocking the others and so the solution was to remove the gradient fill.
I don't have a good answer as how best to approach debugging the charts component though.

Objective C : Get correct float values(justified)

I worked a lot in it and can't find a solution. Even the title can't explain clearly.
I have three values weight, quantity and total
I had done the following
float wq = [[weightarray objectAtIndex:selectedint]floatValue];
float q = [quantity floatValue];
float total = wq * q;
for ex, if
[weightarray objectAtIndex:selectedint] = #"3.14";
quantity = 4;
then the result is
wq = 3.140000 q= 4.000000 total = 12.560000
but I need
wq = 3.14 total = 12.56
what to do?
I searched a lot, someone suggests to use NSDecimal,
NSDecimalNumberHandler *roundingBehavior = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundPlain scale:2 raiseOnExactness:FALSE raiseOnOverflow:TRUE raiseOnUnderflow:TRUE raiseOnDivideByZero:TRUE];
but the scale is not 2 here, wq value may have 3 or four numbers after point.
If the total = 2.30000100 means I need total = 2.300001
how to solve this?
I'm not entirely sure what it is your asking for, but it seems as if you want the values to only display a 2 d.p. In which case you could use a string format like so:
NSString *output = [NSString stringWithFormat:#"float = %.2f", 3.14];
The .2 specifies that the float should be justified to 2 d.p.
Hope this helps
There may be a more direct way to achieve it (which I don't know) but here's a suggestion...
Convert to string as you already do.
Use [myString hasSuffix:#"0"] to see if it ends in zero.
Use [myString substringToindex:[myString length]-1] to create a new string without the final zero.
Repeat.
I know it's not elegant, but unless someone has a better solution, this will at least do what you want.
UPDATE: scratch that - I just discovered [myString stringByTrimmingCharactersInSet:set]. Surely this must be what you need...?
Finally solution found, thanks to Martin
float total = 12.56000;
NSString *s = [NSString stringWithFormat:#"%f", total];
NSLog(#"%#",s);
BOOL success;
success =NO;
while(!success)
{
if ([s hasSuffix:#"0"])
{
s = [s substringWithRange:NSMakeRange(0,[s length]-1)];
}
else if ([s hasSuffix:#"."])
{
s = [s substringWithRange:NSMakeRange(0,[s length]-1)];
success = YES;
}
else
success = YES;
}
NSLog(#"%#",s);
if total = 12.560000 it returns total = 12.56
if total = 12.000000 it returns total = 12
if total = 10.000000 it returns total = 10
if total = 12.3000100 it returns total = 12.30001

How to round a float value with button

Okay so I'm trying to get my values rounded up to the nearest whole number with an IBAction.
So 1.88 -> 2.00 ,
11.40 -> 12.00 ,
111.01 -> 112.00, etc.
-
-(IBAction)roundUp:(id)sender
{
float floatRoundValue=lblTotalRound.text floatValue];
ceilf(floatRoundValue);
NSString *stringRoundValue = [NSString stringWithFormat:#"%1.0f", floatRoundValue];
lblTotalRound.text=stringRoundValue;
}
That's what I got. But it's still rounding down below .5 and to the nearest integer
(Ex. 1.19 -> 1 , i need 1.19 -> 2.00).
I've tried %1.2f but the value doesnt change at all.
What am I doing wrong?
ceilf doesn't modify the value you pass in. It returns a modified value.
floatRoundValue = ceilf(floatRoundValue);
ceilf is a function that returns a value (https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man3/ceil.3.html) , you simply need to change that line to the following.
floatRoundValue = ceilf(floatRoundValue);
So the complete code would in your case it would be something like this.
-(IBAction)roundUp:(id)sender
{
float floatRoundValue=lblTotalRound.text floatValue];
floatRoundValue = ceilf(floatRoundValue);
NSString *stringRoundValue = [NSString stringWithFormat:#"%1.0f", floatRoundValue];
lblTotalRound.text=stringRoundValue;
}
If you need to have a $ sign before :
-(IBAction)roundUp:(id)sender
{
float floatRoundValue=(lblTotalRound.text floatValue];
floatRoundValue = ceilf(floatRoundValue);
NSString *stringRoundValue = [NSString stringWithFormat:#"$%1.0f", floatRoundValue];
lblTotalRound.text=stringRoundValue;
}
NSString Class Reference

UIslider increase 10 by 10

I'm making an UISlider and I don't find how to change the selectable values, I would like the only values possible be 10 by 10.
The slider begins at 82 and ends at 362. I want the possible value to be 82,92,102,.....
I've tried different things but I don't find
[sliderannonce setValue: [sliderannonce value]+10.0 animated:YES];
or
sliderannonce.value=10;
I've my action here:
- (IBAction)changeSliderAnnonce:(id)sender{
labelSliderAnnonce.text = [[NSString alloc] initWithFormat:#"annonce:%d",(int)sliderannonce.value];
}
If you did something like that or you know how to do please let me know.
Wouldn't it be simpler to just multiply the value by 10 in your code and add the starting value?
Example : start the slider at 0, end at 28 :
int position = 82 + ((int)sliderannonce.value) * 10;
Finally found a way to "cheat" with your idea thanks :D
I started to 8,2 and end to 36,2 and I multiply by 10
- (IBAction)changeSliderAnnonce:(id)sender{
int position= ((int)sliderannonce.value)*10+2;
labelSliderAnnonce.text = [[NSString alloc] initWithFormat:#"annonce: %d",((int)sliderannonce.value)*10+ 2];
NSLog(#"valeur de l'enchere: %d",position);
}

How to NSLog pixel RGB from a UIImage?

I just want to:
1) Copy the pixel data.
2) Iterate and Modify each pixel (just show me how to NSLog the ARGB values as 255)
3) Create a UIImage from the new pixel data
I can figure out the the gory details if someone can just tell me how to NSLog the RGBA values of a pixel as 255. How do I modify the following code to do this? Be Specific Please!
-(UIImage*)modifyPixels:(UIImage*)originalImage
{
NSData* pixelData = (NSData*)CGDataProviderCopyData(CGImageGetDataProvider(originalImage.CGImage));
uint myLength = [pixelData length];
for(int i = 0; i < myLength; i += 4) {
//CHANGE PIXELS HERE
/*
Sidenote: Just show me how to NSLog them
*/
//Example:
//NSLog(#"Alpha 255-Value is: %u", data[i]);
//NSLog(#"Red 255-Value is: %u", data[i+1]);
//NSLog(#"Green 255-Value is: %u", data[i+2]);
//NSLog(#"Blue 255-Value is: %u", data[i+3]);
}
//CREATE NEW UIIMAGE (newImage) HERE
return newImage;
}
Did this direction work for you? I'd get pixel data like this:
UInt32 *pixels = CGBitmapContextGetData( ctx );
#define getRed(p) ((p) & 0x000000FF)
#define getGreen(p) ((p) & 0x0000FF00) >> 8
#define getBlue(p) ((p) & 0x00FF0000) >> 16
// display RGB values from the 11th pixel
NSLog(#"Red: %d, Green: %d, Blue: %d", getRed(pixels[10]), getGreen(pixels[10]), getBlue(pixels[10]));
If you'd like to actually see the image, you can use Florent Pillet's NSLogger:
https://github.com/fpillet/NSLogger
The idea is you start the NSLogger client on your desktop, and then in your app you put this up towards the top:
#import "LoggerClient.h"
And in your modifyPixels method you can do something like this:
LogImageData(#"RexOnRoids", // Any identifier to go along with the log
0, // Log level
newImage.size.width, // Image width
newImage.size.height, // Image height
UIImagePNGRepresentation(newImage)); // Image as PNG
Start the client on your desktop, and then run the app on your iphone, and you'll see real images appear in the client. VERY handy for debugging image problems such as flipping, rotating, colors, alpha, etc.