X轴值越来越重叠-iOS图表

时间:2019-09-12 06:14:28

标签: ios swift charts

这是图表视图的屏幕截图。

enter image description here

我正在使用ios https://github.com/danielgindi/Charts

x轴上的值(日期)越来越重叠。

value

这是我写的代码,

 axisMinValue = 50.0
 axixMaxvalue = 300.0

unitsSold = [65.0,88.0, 114.0, 111.0, 88.0 ]
months = ["Sep 12, 2019”,"Sep 12, 2019”,"Sep 12, 2019”,"Sep 11, 2019”,"Sep 11, 2019"]

//在x轴上显示值

    if unitsSold.count < 1{

         cell.chartViewOutlet.noDataText = "No data available!"
    }
    else{

        dataEntries = []
        for i in 0 ..< unitsSold.count {
            let dataEntry = ChartDataEntry(x: Double(i), y: unitsSold[i]) 
            dataEntries.append(dataEntry) // here we add it to the data set
        }

        let lineChartDataSet = LineChartDataSet(values: dataEntries, label: "Units Consumed")

        lineChartDataSet.setCircleColor(UIColor.clear) // hide the outer circle color
        lineChartDataSet.circleRadius = 0.0
        lineChartDataSet.lineWidth = 2.0 //1.0
        lineChartDataSet.valueTextColor = UIColor.clear //hide the values on the curve line


        lineChartDataSet.colors = [NSUIColor.blue] //Sets the line colour to blue
        lineChartDataSet.mode = .cubicBezier
        lineChartDataSet.cubicIntensity = 0.2

        var dataSets = [LineChartDataSet]() 
        dataSets.append(lineChartDataSet)  

        let lineChartData = LineChartData(dataSets: dataSets)
        cell.chartViewOutlet.data = lineChartData 

        cell.chartViewOutlet.chartDescription?.text = "" 

        cell.chartViewOutlet.xAxis.enabled = true 
        cell.chartViewOutlet.leftAxis.enabled = true 
        cell.chartViewOutlet.rightAxis.enabled = false 
        cell.chartViewOutlet.animate(xAxisDuration: 1.5) 
        cell.chartViewOutlet.drawGridBackgroundEnabled = true 




        cell.chartViewOutlet.xAxis.drawGridLinesEnabled = true 
        cell.chartViewOutlet.xAxis.drawAxisLineEnabled = true 

        cell.chartViewOutlet.xAxis.labelPosition = .bottom 
        cell.chartViewOutlet.xAxis.drawLabelsEnabled = true 


        cell.chartViewOutlet.leftAxis.drawGridLinesEnabled = true 

        cell.chartViewOutlet.legend.enabled = false //show.hide legend - below graph


        let customFormater = CustomFormatter1()
        customFormater.labels =  months
        cell.chartViewOutlet.xAxis.valueFormatter = customFormater

我们如何解决这个重叠的问题?还是有任何方法可以使此值根据其屏幕或月份长度自动调整?

1 个答案:

答案 0 :(得分:1)

尝试使用以下内容并尝试,它将可以100%工作

cell.chartViewOutlet.xAxis.labelRotationAngle = -45