ios图表水平条形图问题
自从我更新到ios图表的最新版本(3.0.0)以来,我在水平条形图方面遇到了许多问题 首先,我在图表上有x轴的标签。有了新版本的ios图表,我不得不编写自己的格式化程序,然而现在只有每秒钟显示一次标签。第二个问题是杆未达到y轴上指示的值。我的意思是,如果我给条带一个值4,条带的高度实际上不够长,无法到达y轴上的4.0标签。这两个问题如图所示 以下是我的值格式化程序代码:ios图表水平条形图问题,ios,objective-c,swift,charts,ios-charts,Ios,Objective C,Swift,Charts,Ios Charts,自从我更新到ios图表的最新版本(3.0.0)以来,我在水平条形图方面遇到了许多问题 首先,我在图表上有x轴的标签。有了新版本的ios图表,我不得不编写自己的格式化程序,然而现在只有每秒钟显示一次标签。第二个问题是杆未达到y轴上指示的值。我的意思是,如果我给条带一个值4,条带的高度实际上不够长,无法到达y轴上的4.0标签。这两个问题如图所示 以下是我的值格式化程序代码: @objc(BarChartFormatter) 公共类BarChartFormatter:NSObject、IAxisV
@objc(BarChartFormatter)
公共类BarChartFormatter:NSObject、IAxisValueFormatter{
var labelArray : [String] = ["text1", "text2", "text3", "text4", "text5", "text6", "text7", "text8", "text9", "text10"]
public func stringForValue(_ value: Double, axis: AxisBase?) -> String {
return labelArray[Int(value)]
}
}
这是条形图的代码
horizontalBarChartView.noDataText = "You need to provide data for the chart."
horizontalBarChartView.isUserInteractionEnabled = false
horizontalBarChartView.drawGridBackgroundEnabled = false
horizontalBarChartView.drawValueAboveBarEnabled = false
horizontalBarChartView.legend.enabled = false
horizontalBarChartView.drawBarShadowEnabled = false
horizontalBarChartView.chartDescription?.text = ""
horizontalBarChartView.setExtraOffsets(left: 0, top: 0, right: 0, bottom: 0)
// Right y axis
let barRightAxis = horizontalBarChartView.leftAxis
barRightAxis.drawGridLinesEnabled = false
barRightAxis.enabled = false
let formato:BarChartFormatter = BarChartFormatter()
let xaxis:XAxis = XAxis()
// Left y axis
let barLeftAxis = horizontalBarChartView.rightAxis
let count = 5
barLeftAxis.setLabelCount(count, force: true)
barLeftAxis.drawGridLinesEnabled = false
barLeftAxis.axisLineWidth = 2
barLeftAxis.axisLineColor = UIColor.white
barLeftAxis.labelTextColor = UIColor.white
barLeftAxis.axisMinimum = 0.0
barLeftAxis.axisMaximum = 4.0
barLeftAxis.granularityEnabled = true
barLeftAxis.granularity = 1.0
barLeftAxis.decimals = 0
// x axis
let barXaXis = horizontalBarChartView.xAxis
barXaXis.drawGridLinesEnabled = false
barXaXis.axisLineColor = UIColor.white
barXaXis.axisLineWidth = 2
barXaXis.labelTextColor = UIColor.white
barXaXis.labelPosition = .bottomInside
barXaXis.granularityEnabled = true
barXaXis.granularity = 1.0
barXaXis.decimals = 0
var dataEntries: [BarChartDataEntry] = []
var colors: [UIColor] = []
let theScoreVec = [1.0, 2.0, 3.0, 4.0, 3.0, 0.0, 2.0, 0.0, 1.0, 4.0]
for i in 0..<10 {
let theScore = theScoreVec[i]
if (theScore == 0.0){
colors.append(UIColor.clear)
let dataEntry = BarChartDataEntry(x: Double(i), y : Double(4.0))
dataEntries.append(dataEntry)
} else {
colors.append(UIColor.red)
let dataEntry = BarChartDataEntry(x: Double(i), y: Double(theScore))
dataEntries.append(dataEntry)
}
}
xaxis.valueFormatter = formato
barXaXis.valueFormatter = xaxis.valueFormatter
for i in 0..<10{
formato.stringForValue(Double(i), axis: xaxis)
}
xaxis.valueFormatter = formato
barXaXis.valueFormatter = xaxis.valueFormatter
let chartDataSet = BarChartDataSet(values: dataEntries, label: "Completion")
chartDataSet.colors = colors
let chartData = BarChartData(dataSet: chartDataSet)
chartData.setDrawValues(false)
horizontalBarChartView.data = chartData
horizontalBarChartView.nodata=“您需要为图表提供数据。”
horizontalBarChartView.isUserInteractionEnabled=false
horizontalBarChartView.drawGridBackgroundEnabled=false
horizontalBarChartView.DrawValueUpperBarEnabled=false
horizontalBarChartView.legend.enabled=false
horizontalBarChartView.DrablesHadoEnabled=false
horizontalBarChartView.chartDescription?.text=“”
horizontalBarChartView.setExtraOffsets(左:0,上:0,右:0,下:0)
//右y轴
设barRightAxis=horizontalBarChartView.leftAxis
barRightAxis.drawGridLinesEnabled=false
barRightAxis.enabled=false
let formato:BarChartFormatter=BarChartFormatter()
设xaxis:xaxis=xaxis()
//左y轴
设barLeftAxis=horizontalBarChartView.rightAxis
让计数=5
barLeftAxis.setLabelCount(计数,强制:true)
barLeftAxis.drawGridLinesEnabled=false
barLeftAxis.axisLineWidth=2
barLeftAxis.axisLineColor=UIColor.white
barLeftAxis.labelTextColor=UIColor.white
barLeftAxis.Axis最小值=0.0
barLeftAxis.axisMaximum=4.0
barLeftAxis.granularityEnabled=true
barLeftAxis.granularity=1.0
barLeftAxis.decimals=0
//x轴
设barXaXis=horizontalBarChartView.xAxis
barXaXis.drawGridLinesEnabled=false
barXaXis.axisLineColor=UIColor.white
barXaXis.axisLineWidth=2
barXaXis.labelTextColor=UIColor.white
barXaXis.labelPosition=.bottomInside
barXaXis.granularityEnabled=真
barXaXis.granularity=1.0
barXaXis.decimals=0
var数据项:[BarChartDataEntry]=[]
变量颜色:[UIColor]=[]
让CoreVec=[1.0,2.0,3.0,4.0,3.0,0.0,2.0,0.0,1.0,4.0]
因为我在0。。