First, Introduction
Uuchart is a third party for charting, especially for line charts. You do a hospital related projects, need to monitor the blood pressure within a week, need to draw a line chart to show the direction of high pressure, low pressure, so learning a bit.
Two:
Https://github.com/ZhipingYang/UUChartView
Third, the use
The first step, first we will download the files extracted, there is a Uuchar folder, and then drag the entire folder into the project. We will find that there are UUBar.h, UUChart.h and other documents, these are the concrete implementation of Uuchart.
The second step, we need to introduce in the referenced. h file
#import "UUChart.h"
then implement the proxy
@interface Bloodpressureviewcontroller:baseviewcontroller<uuchartdatasource,requestdelegate>
Then we need to instantiate a uuchart. My own instantiation is: Uuchart *bloodpressurecharview;
Instantiate three arrays:
Nsmutablearray *xvalues; // This is the horizontal axis of the content *yvalues1; // This is the content of the vertical coordinates (high pressure) *yvalues2; // This is the content of the vertical coordinates (low pressure)
The third step, implement the Proxy method
#pragmaMark-uucharview Delegate//the method is to return the horizontal axis of the instantiated line chart-(Nsarray *) Uuchart_xlablearray: (Uuchart *) chart{returnxValues; }//the method is to return the vertical coordinates of the instantiated line chart (if the return is a line chart, I need to show the high pressure here, so I returned two)-(Nsarray *) Uuchart_yvaluearray: (Uuchart *) chart{return@[yvalues1,yvalues2];}//This returns the extent of the ordinate. -(Cgrange) Uuchartchooserangeinlinechart: (Uuchart *) chart{returnCgrangemake ( $,0);}//This is used to set whether the maximum minimum value is displayed. -(BOOL) Uuchart: (Uuchart *) Chart Showmaxminatindex: (nsinteger) index{returnYES;}//Color Array-(Nsarray *) Uuchart_colorarray: (Uuchart *) chart{return@[uugreen,uured,uubrown];}-(BOOL) Uuchart: (Uuchart *) Chart Showhorizonlineatindex: (nsinteger) index{returnYES;}
In the fourth step, we put the data we need to set into three arrays.
On the other hand, I need a function is to put all the points in the line chart of the vertical axis is displayed, so the uuchart slightly modified. Here's how to modify it:
Find UULINECHAR.M and find the following code:
- (void) Addpoint: (cgpoint) point index: (nsinteger) Index isshow: (BOOL) Ishollow value: (cgfloat) value{ UIView*view = [[UIView alloc]initwithframe:cgrectmake (5,5,8,8)]; View.center=Point ; View.layer.masksToBounds=YES; View.layer.cornerRadius=4; View.layer.borderWidth=2; View.layer.borderColor= [[_colors objectatindex:index] cgcolor]?[[_colors Objectatindex:index] cgcolor]:uugreen.cgcolor; if(ishollow) {View.backgroundcolor=[Uicolor Whitecolor]; }Else{View.backgroundcolor= [_colors Objectatindex:index]?[_colors Objectatindex:index]:uugreen; UILabel*label = [[UILabel alloc]initwithframe:cgrectmake (point.x-uutaglabelwidth/2.0, point.y-uulabelheight*2, Uutaglabelwidth, Uulabelheight)]; Label.font= [Uifont systemfontofsize:Ten]; Label.textalignment=Nstextalignmentcenter; Label.textcolor=View.backgroundcolor; Label.text= [NSString stringWithFormat:@"%d",(int) value]; [Self Addsubview:label]; } [self Addsubview:view]; }
We just need to remove the if else judgment. That
- (void) Addpoint: (cgpoint) point index: (nsinteger) Index isshow: (BOOL) Ishollow value: (cgfloat) value{ UIView*view = [[UIView alloc]initwithframe:cgrectmake (5,5,8,8)]; View.center=Point ; View.layer.masksToBounds=YES; View.layer.cornerRadius=4; View.layer.borderWidth=2; View.layer.borderColor= [[_colors objectatindex:index] cgcolor]?[[_colors Objectatindex:index] cgcolor]:uugreen.cgcolor; //if (ishollow) {//View.backgroundcolor = [Uicolor whitecolor];//}else{View.backgroundcolor= [_colors Objectatindex:index]?[_colors Objectatindex:index]:uugreen; UILabel*label = [[UILabel alloc]initwithframe:cgrectmake (point.x-uutaglabelwidth/2.0, point.y-uulabelheight*2, Uutaglabelwidth, Uulabelheight)]; Label.font= [Uifont systemfontofsize:Ten]; Label.textalignment=Nstextalignmentcenter; Label.textcolor=View.backgroundcolor; Label.text= [NSString stringWithFormat:@"%d",(int) value]; [Self Addsubview:label];// }[self Addsubview:view];}
This will show the coordinates of all points. Effect
Additional request to deal with the source code, I hope you use to get
-(void) Requestresult: (Nsdictionary *dic Tag: (nsinteger) tag{if(tag== -) { if([[DiC Objectforkey:@"Code"] intvalue]==0) {Bloodpressurecharview= [[Uuchart alloc] Initwithuuchartdataframe:cgrectmake (0, -, -, -) withsource:self Withstyle:uuchartlinestyle]; Bloodpressuremodel*model =[[Bloodpressuremodel alloc] init]; Nsmutablearray*arr =[model Getweightarrfromdic:dic]; [XValues removeallobjects]; [YValues1 removeallobjects]; [YValues2 removeallobjects]; for(Bloodpressuremodel *moincharr) {[XValues AddObject:mo.weekDay]; [YValues1 AddObject:mo.diastolicPressure]; [YValues2 AddObject:mo.systolicPressure]; } [Bloodpressurecharview ShowInView:self.view]; [Self hudhide]; }Else{[Self hudhide]; Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (0.4* nsec_per_sec)), Dispatch_get_main_queue (), ^{[Self alert:[dic objectforkey:@"msg"]]; }); } }Else{[Self hudhide]; } }View Code
Use of Uuchart