OC调用Charts绘制图表(初始化工具类)

/** 返回只有左Y轴的折线图*/
+ (LineChartView *)lineChartViewForLeftWithDelegate:(id)target
{
    LineChartView *lineChartView = [[LineChartView alloc] init];
    lineChartView.delegate = target;
    lineChartView.backgroundColor = [UIColor whiteColor];
    lineChartView.noDataText = @"";
    lineChartView.descriptionText = @"";
    lineChartView.scaleYEnabled = NO;//取消Y轴缩放
    lineChartView.doubleTapToZoomEnabled = NO;//取消双击缩放
    lineChartView.dragDecelerationEnabled = YES;//拖拽后是否有惯性效果
    lineChartView.dragDecelerationFrictionCoef = 0.9;//拖拽后惯性效果的摩擦系数(0~1),数值越小,惯性越不明显
    lineChartView.xAxis.labelPosition = XAxisLabelPositionBottom;//X轴的显示位置,
    //        不绘制 右-y轴
    lineChartView.rightAxis.enabled = NO;
    //        x 轴
    lineChartView.xAxis.axisLineWidth = 0.5;
    lineChartView.xAxis.axisLineColor =  RGB(40, 40, 40);
    //        网格线 纵线
    lineChartView.xAxis.gridLineWidth = 0.5;
    lineChartView.xAxis.gridColor = RGB(235, 235, 235);
    //        左侧 y轴
    lineChartView.leftAxis.axisLineWidth = 0.5;
    lineChartView.leftAxis.axisLineColor =  RGB(40, 40, 40);
    //      左侧网格线  横线
    lineChartView.leftAxis.gridLineWidth = 0.5;
    lineChartView.leftAxis.gridColor = RGB(235, 235, 235);
    //    图标右下角 描述文字
    lineChartView.legend.form = ChartLegendFormSquare;
    //    legend  图例 大小
    lineChartView.legend.formSize = 10;
    //    图例文字颜色
    lineChartView.legend.textColor = RGB(242, 152, 80);
    lineChartView.xAxis.valueFormatter = target;
    return lineChartView;
}
/** 返回有左右Y轴的折线图*/
+ (LineChartView *)lineChartViewForBothWithDelegate:(id)target;
{
    LineChartView *lineChartView =  [[LineChartView alloc] init];
    lineChartView.delegate = target;
    lineChartView.backgroundColor = [UIColor whiteColor];
    lineChartView.noDataText = @"";
    lineChartView.descriptionText = @"";
    lineChartView.scaleYEnabled = NO;//取消Y轴缩放
    lineChartView.doubleTapToZoomEnabled = NO;//取消双击缩放
    lineChartView.dragDecelerationEnabled = YES;//拖拽后是否有惯性效果
    lineChartView.dragDecelerationFrictionCoef = 0.9;//拖拽后惯性效果的摩擦系数(0~1),数值越小,惯性越不明显
    lineChartView.xAxis.labelPosition = XAxisLabelPositionBottom;//X轴的显示位置,默认是显示在上面的
    //        左侧 Y轴的起点和最大最小值、个数、未确定
    //        x 轴
    lineChartView.xAxis.axisLineWidth = 0.5;
    lineChartView.xAxis.axisLineColor =  RGB(40, 40, 40);
    //        网格线 纵线
    lineChartView.xAxis.gridLineWidth = 0.5;
    lineChartView.xAxis.gridColor = RGB(235, 235, 235);
    //        左侧 y 周
    lineChartView.leftAxis.axisLineWidth = 0.5;
    lineChartView.leftAxis.axisLineColor =  RGB(40, 40, 40);
    //      左侧网格线  横线
    lineChartView.leftAxis.gridLineWidth = 0.5;
    lineChartView.leftAxis.gridColor = RGB(235, 235, 235);
    //        右侧 y周
    lineChartView.rightAxis.axisLineWidth = 0.5;
    lineChartView.rightAxis.axisLineColor = RGB(40, 40, 40);
    //      右侧网格线  横线
    lineChartView.rightAxis.gridLineWidth = 0.5;
    lineChartView.rightAxis.gridColor = RGB(235, 235, 235);
    //        右侧网 横线
    //    图标右下角 描述文字
    lineChartView.legend.form = ChartLegendFormLine;
    //    legend  图例 大小
    lineChartView.legend.formSize = 10;
    //    图例文字颜色
    lineChartView.legend.textColor = RGB(242, 152, 80);
    lineChartView.xAxis.valueFormatter = target;
    return lineChartView;
}
/** 返回只有左Y轴的柱状图*/
+ (BarChartView *)barChartViewWithDelegate:(id)target
{
    BarChartView *barChartView = [[BarChartView alloc] init];
    barChartView.delegate = target;
    //  描述文字  无数据文字
    barChartView.chartDescription.enabled = NO;
    barChartView.noDataText = @"";
    //   捏合手势 与 双击手势
    barChartView.pinchZoomEnabled = NO;
    barChartView.doubleTapToZoomEnabled = NO;
    //  是否允许x、y轴进行缩放
    barChartView.scaleYEnabled = NO;
    barChartView.scaleXEnabled = NO;
    barChartView.drawBarShadowEnabled = NO;
    barChartView.drawGridBackgroundEnabled = NO;
    //  图例设置
    barChartView.legend.position = ChartLegendPositionBelowChartLeft;
    barChartView.legend.font = [UIFont systemFontOfSize:10.f];
    //  取消高亮
    barChartView.highlightPerTapEnabled = NO;
    barChartView.xAxis.drawGridLinesEnabled = NO;
    barChartView.xAxis.labelPosition = XAxisLabelPositionBottom;
    barChartView.xAxis.labelFont = [UIFont systemFontOfSize:10.f];
    barChartView.xAxis.granularity = 1.f;
    barChartView.xAxis.centerAxisLabelsEnabled = YES;
    barChartView.xAxis.valueFormatter = target;
    //   左 x 轴
    barChartView.leftAxis.gridLineWidth = 0.5;
    
    barChartView.leftAxis.gridColor = RGB(235, 235, 235);
    barChartView.leftAxis.labelFont = [UIFont systemFontOfSize:10.f];
    barChartView.leftAxis.spaceTop = 0.35;
    barChartView.rightAxis.enabled = NO;
    [barChartView zoomWithScaleX:2.5 scaleY:1 x:1 y:0];
    return barChartView;
}
/** 返回有左右Y轴的混合图(折线图&&柱状图)*/
+ (CombinedChartView *)comChartViewWithDelegate:(id)target
{
    CombinedChartView *comChartView = [[CombinedChartView alloc] init];
    comChartView.delegate = target;
    //  描述文字  无数据文字
    comChartView.chartDescription.enabled = NO;
    comChartView.noDataText = @"";
    //   捏合手势 与 双击手势
    comChartView.pinchZoomEnabled = NO;
    comChartView.doubleTapToZoomEnabled = NO;
    //  是否允许x、y轴进行缩放
    comChartView.scaleYEnabled = NO;
    comChartView.scaleXEnabled = NO;
    comChartView.drawGridBackgroundEnabled = NO;
    comChartView.drawBarShadowEnabled = NO;
    comChartView.highlightPerTapEnabled = NO;
    comChartView.drawOrder = @[ @(CombinedChartDrawOrderBar), @(CombinedChartDrawOrderLine)];
    comChartView.legend.position = ChartLegendPositionBelowChartLeft;
    comChartView.legend.font = [UIFont systemFontOfSize:10.f];
    comChartView.leftAxis.gridLineWidth = 0.5;
    comChartView.leftAxis.gridColor = RGB(235, 235, 235);
    comChartView.leftAxis.labelFont = [UIFont systemFontOfSize:10.f];
    comChartView.leftAxis.spaceTop = 0.35;
    comChartView.rightAxis.gridLineWidth = 0.5;
    comChartView.rightAxis.gridColor = RGB(235, 235, 235);
    comChartView.rightAxis.labelFont = [UIFont systemFontOfSize:10.f];
    comChartView.rightAxis.spaceTop = 0.35;
    comChartView.xAxis.labelPosition = XAxisLabelPositionBottom;
    comChartView.xAxis.granularity = 1.0;
    comChartView.xAxis.valueFormatter = target;
    comChartView.xAxis.drawGridLinesEnabled = NO;
    return comChartView;
}

你可能感兴趣的:(OC调用Charts绘制图表(初始化工具类))