柱状图设置

// 设置XY轴动画
    [barView animateWithYAxisDuration:1.0f];
    [barView animateWithXAxisDuration:1.0f];
    // 是否绘制阴影背景
    barView.drawBarShadowEnabled = NO;
    // 数值显示是否在条柱上面
    barView.drawValueAboveBarEnabled = YES;
    // 没有数据的时候的显示
    barView.noDataText = @"暂无数据";
    barView.noDataFont = [UIFont systemFontOfSize:16];
    barView.noDataTextColor = [UIColor whiteColor];
    // 是否画右边坐标轴
    barView.rightAxis.enabled = NO;
    //是否画图例(图例的具体配置可参照我的饼状图)
    barView.legend.enabled = NO;
    // 是否可以拖拽设置
    barView.dragEnabled = YES;
    // 双击是否缩放
    barView.doubleTapToZoomEnabled = NO;
    // XY轴是否缩放
    barView.scaleXEnabled = NO;//X轴缩放
    barView.scaleYEnabled = NO;//Y轴缩放
    // XY轴是否可以同时缩放
    barView.pinchZoomEnabled = NO;
    // 是否开启描述label
    barView.chartDescription.enabled = NO;
    barView.delegate=self;
    ChartXAxis *xAxis = barView.xAxis;// 获取X轴
    xAxis.labelPosition = XAxisLabelPositionBottom;// X轴的显示位置
    xAxis.drawGridLinesEnabled = NO; // 是否绘制网格
    xAxis.labelFont = [UIFont fontWithName:@"Helvetica-Bold" size:10.0f];// X轴数值上面的字体 大小
    xAxis.labelTextColor = [UIColor darkGrayColor];// X轴数值颜色
    xAxis.labelWidth=10;// X轴label宽度
    xAxis.labelCount=12;// X轴显示的label数量
    xAxis.gridLineDashLengths = @[@3.0f, @3.0f];// 设置虚线样式的网格线
    xAxis.gridColor = [UIColor colorWithRed:153/255.f green:153/255.f blue:153/255.f alpha:1];// 网格线颜色
    xAxis.gridAntialiasEnabled = YES;
    xAxis.valueFormatter = self;
    
    ChartYAxis *leftAxis = barView.leftAxis;// 获取Y轴
    NSNumberFormatter *leftAxisFormatter = [[NSNumberFormatter alloc] init];// 坐标数值样式
    leftAxisFormatter.maximumFractionDigits=1;// Y轴坐标最多为1位小数
    leftAxis.drawGridLinesEnabled = YES; // 是否绘制网格
    leftAxis.gridLineDashLengths = @[@5.f, @5.f];
    leftAxis.valueFormatter = [[ChartDefaultAxisValueFormatter alloc] initWithFormatter:leftAxisFormatter];
    leftAxis.axisMinimum=0;// 最小值
    leftAxis.labelPosition = YAxisLabelPositionOutsideChart;// 坐标数值的位置
    leftAxis.labelTextColor = [UIColor darkGrayColor];// Y轴数值颜色
    leftAxis.labelCount=4;// 数值分割个数
    leftAxis.spaceTop=0.15;// 最大值到顶部的范围比
    
    BalloonMarker *marker = [[BalloonMarker alloc]
                             initWithColor: [UIColor colorWithWhite:180/255. alpha:1.0]
                             font: [UIFont systemFontOfSize:12.0]
                             textColor: UIColor.whiteColor
                             insets: UIEdgeInsetsMake(8.0, 8.0, 20.0, 8.0)];
    marker.chartView = barView;
    marker.minimumSize = CGSizeMake(80.f, 40.f);
    barView.marker = marker;

你可能感兴趣的:(柱状图设置)