ios图表中单个X轴值的多个值

时间:2016-08-11 05:47:07

标签: ios charts ios-charts

我在我的应用程序中使用条形图。我的要求是我必须为单个X轴值绘制五个值。它可能在ios图表中吗? 请帮帮我!

    var dataEntries: [BarChartDataEntry] = []
    let xAxis:ChartXAxis = Barchartviews.xAxis
    xAxis.drawAxisLineEnabled = false
    xAxis.drawGridLinesEnabled = false
    xAxis.getLongestLabel()
    xAxis.avoidFirstLastClippingEnabled=true
    xAxis.spaceBetweenLabels=10


    for i in 0..<dataPoints.count {
        let dataEntry = BarChartDataEntry(value: values[i], xIndex: i)
        dataEntries.append(dataEntry)
    }

    let chartDataSet = BarChartDataSet(yVals: dataEntries, label: "Units Sold")
     chartDataSet.colors = ChartColorTemplates.joyful()
    let chartData = BarChartData(xVals: Barmonths, dataSet: chartDataSet)
    Barchartviews.data = chartData

    let chartData1 = BarChartData(xVals: Barmonths, dataSet: chartDataSet)
    Barchartviews.data = chartData1

    Barchartviews.legend.enabled=false
    Barchartviews.animate(xAxisDuration: 2.0, yAxisDuration: 2.0)

1 个答案:

答案 0 :(得分:0)

   let groupSpace = 0.3
    let barSpace = 0.05
    let barWidth = 0.3

    // it should be like (groupSpace + barSpace) * 2 + barWidth = 1.0

    let groupCount = self.days.count // days is Array for xAxis labels
    let startDay = 0.0

    barChartData.barWidth = barWidth
    barChartView.xAxis.axisMinimum = startDay

    let gpWidth = barChartData.groupWidth(groupSpace: groupSpace, barSpace: barSpace)
    barChartView.xAxis.axisMaximum = startDay + gpWidth * Double(groupCount)

    barChartData.groupBars(fromX: startDay, groupSpace: groupSpace, barSpace: barSpace)
    barChartView.notifyDataSetChanged()