下面的這些代碼呢是在oc工程裏裏使用的 其實和在swift中使用沒什麼大的差異 屬性都同樣的web
//建立餅狀圖
self.pieChartView = [[PieChartView alloc] initWithFrame:CGRectMake(20, 80, f_Device_w-40, 300)];
[self.view addSubview:self.pieChartView];
//基本樣式
[self.pieChartView setExtraOffsetsWithLeft:30 top:0 right:30 bottom:0];//餅狀圖距離邊緣的間隙
self.pieChartView.usePercentValuesEnabled = YES;//是否根據所提供的數據, 將顯示數據轉換爲百分比格式
self.pieChartView.dragDecelerationEnabled = YES;//拖拽餅狀圖後是否有慣性效果
self.pieChartView.drawSliceTextEnabled = YES;//是否顯示區塊文本
//空心餅狀圖樣式
self.pieChartView.drawHoleEnabled = YES;//餅狀圖是不是空心
self.pieChartView.holeRadiusPercent = 0.5;//空心半徑佔比
self.pieChartView.holeColor = [UIColor clearColor];//空心顏色
self.pieChartView.transparentCircleRadiusPercent = 0.52;//半透明空心半徑佔比
self.pieChartView.transparentCircleColor = [UIColor colorWithRed:210/255.0 green:145/255.0 blue:165/255.0 alpha:0.3];//半透明空心的顏色
//實心餅狀圖樣式
// self.pieChartView.drawHoleEnabled = NO;
//餅狀圖中間描述
if (self.pieChartView.isDrawHoleEnabled == YES) {
self.pieChartView.drawCenterTextEnabled = YES;//是否顯示中間文字
//普通文本
// self.pieChartView.centerText = @"餅狀圖";//中間文字
//富文本
NSMutableAttributedString *centerText = [[NSMutableAttributedString alloc] initWithString:@"餅狀圖"];
[centerText setAttributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:16],NSForegroundColorAttributeName: [UIColor orangeColor]} range:NSMakeRange(0, centerText.length)];
self.pieChartView.centerAttributedText = centerText;
}
//餅狀圖描述
self.pieChartView.descriptionText = @"餅狀圖示例";
self.pieChartView.descriptionFont = [UIFont systemFontOfSize:10];
self.pieChartView.descriptionTextColor = [UIColor grayColor];
//餅狀圖圖例
self.pieChartView.legend.maxSizePercent = 1;//圖例在餅狀圖中的大小佔比, 這會影響圖例的寬高
self.pieChartView.legend.formToTextSpace = 5;//文本間隔
self.pieChartView.legend.font = [UIFont systemFontOfSize:10];//字體大小
self.pieChartView.legend.textColor = [UIColor grayColor];//字體顏色
self.pieChartView.legend.position = ChartLegendPositionBelowChartCenter;//圖例在餅狀圖中的位置
self.pieChartView.legend.form = ChartLegendFormCircle;//圖示樣式: 方形、線條、圓形
self.pieChartView.legend.formSize = 12;//圖示大小
//爲餅狀圖提供數據
self.pieCData = [self setData];
self.pieChartView.data = self.pieCData;
//設置動畫效果
[self.pieChartView animateWithXAxisDuration:1.0f easingOption:ChartEasingOptionEaseOutExpo];swift
雷達圖:ide
//建立雷達圖對象
self.radarChartView = [[RadarChartView alloc] initWithFrame:CGRectMake(20, 80, f_Device_w-40, 300)];
[self.view addSubview:self.radarChartView];
self.radarChartView.delegate = self;
self.radarChartView.descriptionText = @"";//描述
self.radarChartView.rotationEnabled = YES;//是否容許轉動
self.radarChartView.highlightPerTapEnabled = YES;//是否能被選中
//雷達圖線條樣式
self.radarChartView.webLineWidth = 0.5;//主幹線線寬
self.radarChartView.webColor = [self colorWithHexString:@"#c2ccd0"];//主幹線線寬
self.radarChartView.innerWebLineWidth = 0.375;//邊線寬度
self.radarChartView.innerWebColor = [self colorWithHexString:@"#c2ccd0"];//邊線顏色
self.radarChartView.webAlpha = 1;//透明度
//設置 xAxi
ChartXAxis *xAxis = self.radarChartView.xAxis;
xAxis.labelFont = [UIFont systemFontOfSize:15];//字體
xAxis.labelTextColor = [self colorWithHexString:@"#057748"];//顏色
//設置 yAxis
ChartYAxis *yAxis = self.radarChartView.yAxis;
yAxis.axisMinValue = 0.0;//最小值
yAxis.axisMaxValue = 150.0;//最大值
yAxis.drawLabelsEnabled = NO;//是否顯示 label
yAxis.labelCount = 6;// label 個數
yAxis.labelFont = [UIFont systemFontOfSize:9];// label 字體
yAxis.labelTextColor = [UIColor lightGrayColor];// label 顏色
//爲雷達圖提供數據
self.radarCData = [self setData];
self.radarChartView.data = self.radarCData;
[self.radarChartView renderer];
//設置動畫
[self.radarChartView animateWithYAxisDuration:0.1f];字體
柱狀圖:動畫
//添加barChartView
self.barChartView = [[BarChartView alloc] initWithFrame:CGRectMake(20, 80, f_Device_w-40, 300)];
self.barChartView.delegate = self;//設置代理
[self.view addSubview:self.barChartView];
//基本樣式
self.barChartView.backgroundColor = [UIColor colorWithRed:230/255.0f green:253/255.0f blue:253/255.0f alpha:1];
self.barChartView.noDataText = @"暫無數據";//沒有數據時的文字提示
self.barChartView.drawValueAboveBarEnabled = YES;//數值顯示在柱形的上面仍是下面
self.barChartView.drawHighlightArrowEnabled = NO;//點擊柱形圖是否顯示箭頭
self.barChartView.drawBarShadowEnabled = NO;//是否繪製柱形的陰影背景
//交互設置
self.barChartView.scaleYEnabled = NO;//取消Y軸縮放
self.barChartView.doubleTapToZoomEnabled = NO;//取消雙擊縮放
self.barChartView.dragEnabled = YES;//啓用拖拽圖表
self.barChartView.dragDecelerationEnabled = YES;//拖拽後是否有慣性效果
self.barChartView.dragDecelerationFrictionCoef = 0.9;//拖拽後慣性效果的摩擦係數(0~1),數值越小,慣性越不明顯
//X軸樣式
ChartXAxis *xAxis = self.barChartView.xAxis;
xAxis.axisLineWidth = 1;//設置X軸線寬
xAxis.labelPosition = XAxisLabelPositionBottom;//X軸的顯示位置,默認是顯示在上面的
xAxis.drawGridLinesEnabled = NO;//不繪製網格線
xAxis.spaceBetweenLabels = 4;//設置label間隔,若設置爲1,則若是能所有顯示,則每一個柱形下面都會顯示label
xAxis.labelTextColor = [UIColor brownColor];//label文字顏色
//右邊Y軸樣式
self.barChartView.rightAxis.enabled = NO;//不繪製右邊軸
//左邊Y軸樣式
ChartYAxis *leftAxis = self.barChartView.leftAxis;//獲取左邊Y軸
leftAxis.labelCount = 5;//Y軸label數量,數值不必定,若是forceLabelsEnabled等於YES, 則強制繪製制定數量的label, 可是可能不平均
leftAxis.forceLabelsEnabled = NO;//不強制繪製制定數量的label
leftAxis.showOnlyMinMaxEnabled = NO;//是否只顯示最大值和最小值
leftAxis.axisMinValue = 0;//設置Y軸的最小值
leftAxis.startAtZeroEnabled = YES;//從0開始繪製
leftAxis.axisMaxValue = 105;//設置Y軸的最大值
leftAxis.inverted = NO;//是否將Y軸進行上下翻轉
leftAxis.axisLineWidth = 0.5;//Y軸線寬
leftAxis.axisLineColor = [UIColor blackColor];//Y軸顏色
leftAxis.valueFormatter = [[NSNumberFormatter alloc] init];//自定義格式
leftAxis.valueFormatter.positiveSuffix = @" $";//數字後綴單位
leftAxis.labelPosition = YAxisLabelPositionOutsideChart;//label位置
leftAxis.labelTextColor = [UIColor brownColor];//文字顏色
leftAxis.labelFont = [UIFont systemFontOfSize:10.0f];//文字字體
//網格線樣式
leftAxis.gridLineDashLengths = @[@3.0f, @3.0f];//設置虛線樣式的網格線
leftAxis.gridColor = [UIColor colorWithRed:200/255.0f green:200/255.0f blue:200/255.0f alpha:1];//網格線顏色
leftAxis.gridAntialiasEnabled = YES;//開啓抗鋸齒
//添加限制線
ChartLimitLine *limitLine = [[ChartLimitLine alloc] initWithLimit:80 label:@"限制線"];
limitLine.lineWidth = 2;
limitLine.lineColor = [UIColor greenColor];
limitLine.lineDashLengths = @[@5.0f, @5.0f];//虛線樣式
limitLine.labelPosition = ChartLimitLabelPositionRightTop;//位置
[leftAxis addLimitLine:limitLine];//添加到Y軸上
leftAxis.drawLimitLinesBehindDataEnabled = YES;//設置限制線繪製在柱形圖的後面
//圖例說明樣式
self.barChartView.legend.enabled = NO;//不顯示圖例說明
// self.barChartView.legend.position = ChartLegendPositionBelowChartLeft;//位置
//右下角的description文字樣式
self.barChartView.descriptionText = @"";//不顯示,就設爲空字符串便可
// self.barChartView.descriptionText = @"柱形圖";
self.barCData = [self setData];
//爲柱形圖提供數據
self.barChartView.data = self.barCData;
//設置動畫效果,能夠設置X軸和Y軸的動畫效果
[self.barChartView animateWithYAxisDuration:1.0f];spa
折線圖:代理
//添加折線視圖LineChartView
self.LineChartView = [[LineChartView alloc] initWithFrame:CGRectMake(20, 80, f_Device_w-40, 300)];
self.LineChartView.delegate = self;//設置代理
[self.view addSubview:self.LineChartView];
//基本樣式
self.LineChartView.backgroundColor = [UIColor colorWithRed:230/255.0f green:253/255.0f blue:253/255.0f alpha:1];
self.LineChartView.noDataText = @"暫無數據";
//交互樣式
self.LineChartView.scaleYEnabled = NO;//取消Y軸縮放
self.LineChartView.doubleTapToZoomEnabled = NO;//取消雙擊縮放
self.LineChartView.dragEnabled = YES;//啓用拖拽圖標
self.LineChartView.dragDecelerationEnabled = YES;//拖拽後是否有慣性效果
self.LineChartView.dragDecelerationFrictionCoef = 0.9;//拖拽後慣性效果的摩擦係數(0~1),數值越小,慣性越不明顯
//X軸樣式
ChartXAxis *xAxis = self.LineChartView.xAxis;
xAxis.axisLineWidth = 1.0/[UIScreen mainScreen].scale;//設置X軸線寬
xAxis.labelPosition = XAxisLabelPositionBottom;//X軸的顯示位置,默認是顯示在上面的
xAxis.drawGridLinesEnabled = NO;//不繪製網格線
xAxis.spaceBetweenLabels = 4;//設置label間隔
xAxis.labelTextColor = [self colorWithHexString:@"#057748"];//label文字顏色
//Y軸樣式
self.LineChartView.rightAxis.enabled = NO;//不繪製右邊軸
ChartYAxis *leftAxis = self.LineChartView.leftAxis;//獲取左邊Y軸
leftAxis.labelCount = 5;//Y軸label數量,數值不必定,若是forceLabelsEnabled等於YES, 則強制繪製制定數量的label, 可是可能不平均
leftAxis.forceLabelsEnabled = NO;//不強制繪製指定數量的label
leftAxis.showOnlyMinMaxEnabled = NO;//是否只顯示最大值和最小值
leftAxis.axisMinValue = 0;//設置Y軸的最小值
leftAxis.startAtZeroEnabled = YES;//從0開始繪製
leftAxis.axisMaxValue = 105;//設置Y軸的最大值
leftAxis.inverted = NO;//是否將Y軸進行上下翻轉
leftAxis.axisLineWidth = 1.0/[UIScreen mainScreen].scale;//Y軸線寬
leftAxis.axisLineColor = [UIColor blackColor];//Y軸顏色
leftAxis.valueFormatter = [[NSNumberFormatter alloc] init];//自定義格式
leftAxis.valueFormatter.positiveSuffix = @" $";//數字後綴單位
leftAxis.labelPosition = YAxisLabelPositionOutsideChart;//label位置
leftAxis.labelTextColor = [self colorWithHexString:@"#057748"];//文字顏色
leftAxis.labelFont = [UIFont systemFontOfSize:10.0f];//文字字體
//網格線樣式
leftAxis.gridLineDashLengths = @[@3.0f, @3.0f];//設置虛線樣式的網格線
leftAxis.gridColor = [UIColor colorWithRed:200/255.0f green:200/255.0f blue:200/255.0f alpha:1];//網格線顏色
leftAxis.gridAntialiasEnabled = YES;//開啓抗鋸齒
//添加限制線
ChartLimitLine *limitLine = [[ChartLimitLine alloc] initWithLimit:80 label:@"限制線"];
limitLine.lineWidth = 2;
limitLine.lineColor = [UIColor greenColor];
limitLine.lineDashLengths = @[@5.0f, @5.0f];//虛線樣式
limitLine.labelPosition = ChartLimitLabelPositionRightTop;//位置
limitLine.valueTextColor = [self colorWithHexString:@"#057748"];//label文字顏色
limitLine.valueFont = [UIFont systemFontOfSize:12];//label字體
[leftAxis addLimitLine:limitLine];//添加到Y軸上
leftAxis.drawLimitLinesBehindDataEnabled = YES;//設置限制線繪製在折線圖的後面
//描述及圖例樣式
[self.LineChartView setDescriptionText:@"折線圖"];
[self.LineChartView setDescriptionTextColor:[UIColor darkGrayColor]];
self.LineChartView.legend.form = ChartLegendFormLine;
self.LineChartView.legend.formSize = 30;
self.LineChartView.legend.textColor = [UIColor darkGrayColor];
self.lineCData = [self setData];
self.LineChartView.data = self.lineCData;
[self.LineChartView animateWithXAxisDuration:1.0f];orm
界面效果:對象