gpt4 book ai didi

ios - 带有 valueFormatter 的 Swift Charts 模块

转载 作者:行者123 更新时间:2023-11-30 13:31:07 24 4
gpt4 key购买 nike

我正在使用 Swift 图表,我的 x 轴是月份数组 [0,0.5,1.5,...,240] 但我想在 x 轴上显示的是年,所以我的新 x 轴将是 [0.0, 1,2,3...,20];我用了

lineChartView.xAxis.setLabelsToSkip(23)

现在我被格式化部分困住了,我不知道如何将 x 数组格式化为整数,而且已经好几年了。

最佳答案

这是我用来绘制图表的,我不知道如何使用:

lineChartView.xAxis.valueFormatter?.stringForXValue(Int, original: String, viewPortHandler: lineChartView.viewPortHandler)

我尝试使用其他解决方案中提到的覆盖函数,但它没有调用。

   var dataSets : [LineChartDataSet] = [LineChartDataSet]();
dataSets.append(getLineChartData(xArr, y: p3Arr,name:"p3",color: UIColor.blueColor().colorWithAlphaComponent(0.5)))
dataSets.append(getLineChartData(xArr, y: p5Arr,name:"p5",color: UIColor.redColor().colorWithAlphaComponent(0.5)))
dataSets.append(getLineChartData(xArr, y: p10Arr,name:"p10",color: UIColor.greenColor().colorWithAlphaComponent(0.5)))
dataSets.append(getLineChartData(xArr, y: p25Arr,name:"p25",color: UIColor.grayColor().colorWithAlphaComponent(0.5)))
dataSets.append(getLineChartData(xArr, y: p50Arr,name:"p50",color: UIColor.purpleColor().colorWithAlphaComponent(0.5)))
dataSets.append(getLineChartData(xArr, y: p75Arr,name:"p75",color: UIColor.yellowColor().colorWithAlphaComponent(0.5)))
dataSets.append(getLineChartData(xArr, y: p90Arr,name:"p90",color: UIColor.orangeColor().colorWithAlphaComponent(0.5)))
dataSets.append(getLineChartData(xArr, y: p95Arr,name:"p95",color: UIColor.brownColor().colorWithAlphaComponent(0.5)))
dataSets.append(getLineChartData(xArr, y: p97Arr,name:"p97",color: UIColor.cyanColor().colorWithAlphaComponent(0.5)))
//4 - pass our months in for our x-axis label value along with our dataSets
let data: LineChartData = LineChartData(xVals: xArr, dataSets: dataSets)
data.setValueTextColor(UIColor.redColor());

lineChartView.xAxis.setLabelsToSkip(23);

lineChartView.pinchZoomEnabled = false;
lineChartView.doubleTapToZoomEnabled = false;

//lineChartView.xAxis.valueFormatter?.stringForXValue(12, original: "", viewPortHandler: lineChartView.viewPortHandler)
lineChartView.data = data

关于ios - 带有 valueFormatter 的 Swift Charts 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36576436/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com