Coreplot tips: Set the padding:
Graph. plotareaframe. paddingleft + = 5;
Graph. plotareaframe. paddingtop + = 5;
Graph. plotareaframe. paddingright + = 5;
Graph. plotareaframe. paddingbottom ++ = 17.5;
Disable zooming: (two actions)
[Selfsetallowpinchscaling: No]; // disable Scaling
Set coordinates to slide horizontally only according to the X axis: (for other directions, please understand)
Plotspace. yrange = [cptplotrangeplotrangewithlocation: cptdecimalfromint (0) Length: cptdecimalfromfloat (1)];
Plotspace. globalyrange = [cptplotrangeplotrangewithlocation: cptdecimalfromint (0) Length: cptdecimalfromfloat (1)];
Plotspace. xrange = [cptplotrangeplotrangewithlocation: cptdecimalfromint (1) Length: cptdecimalfromfloat (1)];
Plotspace. globalxrange = [cptplotrangeplotrangewithlocation: cptdecimalfromint (0) Length: cptdecimalfromfloat (2)];
Custom axis label:
X. axislabels = [self buildlabeltitle];
X. labelingpolicy =
Cptaxislabelingpolicynone;// After this policy is set, the Axis label and the background line tick need to be drawn by themselves; otherwise, the display is empty. Do not panic too much.
X. minorticklocations = [nssetsetwitharray: locationlabels];
-(Nsmutableset *) buildlabeltitle
{
Nsmutableset * newaxislabels = [nsmutablesetset];
Cptmutabletextstyle * textstyleb = [cptmutabletextstyletextstyle];
Textstyleb. color = [cptcolorcolorwithcomponentred: cptfloat (float) 0x09/0 xff) Green: cptfloat (float) 0x31/0 xff) Blue: cptfloat (float) 0x4a/0xff) ALPHA: cptfloat (1.0)];
Int n = 1;
For (nsuinteger I = 30; I>
0; I --)
{
Cptaxislabel * newlabel = [[cptaxislabelalloc]
Initwithtext: @"Here is the content"
Textstyle: textstyleb];
Newlabel. ticklocation = cptdecimalfromunsignedinteger (N ++ );
Newlabel. offset =
5;
[Locationlabels
Addobject: [nsnumber numberwithfloat :( N-1)-0.25];
[Locationlabels
Addobject: [nsnumber numberwithfloat :( N-1) + 0.25];
[Newaxislabels addobject: newlabel];
[Newlabel release];
}
Return newaxislabels;
}
Refresh the Chart content:
[[Bar1graph]
Reloaddata];
Organize data sources:
[M_so2onlinecaddobject: [nsmutabledictionarydictionarywithobjectsandkeys: X,
@ "X", Y, @ "Y ",
Nil];
If (tmpy> max_data)
{
Max_data = tmpy;
}
Use data sources:
If ([(nsstring *) plot. identifierisstring tostring: kbar1])
{
Switch (fieldenum)
{
Casecptbarplotfieldbarlocation:
Number = [[m_so2onlinecobjectatindex: Index]
Valueforkey: @ "X"] doublevalue];
Break;
Casecptbarplotfieldbartip:
Number = [[m_so2onlinecobjectatindex: Index]
Valueforkey: @ "Y"] doublevalue]/
Max_data;
Break;
Default:
Break;
}
}
The reason for recording max_data is that it is best to use real data here.Relative dataOtherwise, when the data value is large, coreplot performance will be consumed, resulting in slow graph loading.
Calling Data initialization with delayed functions can increase the loading speed:
[Selfperformselector: @ selector (initplotdata) withobject: nilafterdelay: 0.2];
A Simple Method for Calculating dates:
Nsdatecomponents * comps = [[nsdatecomponentsalloc] init];
[Comps setday:-I];
Nsdate * newdate = [[nscalendarcurrentcalendar]
Datebyaddingcomponents: compstodate: [nsdate date] Options: 0];
--------------------------------------------------------
IOS memory optimization and troubleshooting
1. The iboutlet object requires release
2. Add the same subview to uiview, especially uiscrollview. Remember to clear the previous subview and execute this method in the dealloc function.
For (uiview * sbviewin
Scrvbg. subviews)
{
[Sbview removefromsuperview];
}
Here is a tip for getting subview:
[Subview settag: 300];
Subview = [self. viewviewwithtag: 300]
3. dealloc may not be called, so you can manually write a myrelease method. When you exit the interface, manually call the object to be released by release and set it to nil.
4. Remember, if you do not quite understand the call time of drawrect of uiview, do not write code into drawrect easily, especially for objects without immediate release. It is easy to cause memory overflow because drawrect is called multiple times without release.
5. xcode is the best tool to check for Memory leakage. Of course, it is not said that the xcode tool is OK after troubleshooting. We found that xcode can only check for obvious code-level leaks. For example, in the fourth point above, the logic leakage caused by multiple calls to a function but no matching release is not found, you can only read and troubleshoot through code.
My experience here is that alloc objects should be immediately release. If the object cannot be immediately release, make sure that alloc and release must be called in pairs,Pay special attention to the functions that can be called multiple times and contain alloc but are not promptly release.Four words are summarized as "very dangerous "!
6. Do not use self. To alloc an attribute object, for example:
Self. my_arr = [[nsarray alloc] init]; ---------- error!
Nsarray * tmparr = [[nsarray alloc] init];
Self. My = tmparr;
[Tmparr release];
---------- Correct