gpt4 book ai didi

android - 将负值设置到水平条形图中条形的左侧

转载 作者:行者123 更新时间:2023-11-30 04:53:57 26 4
gpt4 key购买 nike

我想将条形的负值设置到条形的左侧,但目前一些条形与这些值重叠。

我怎样才能消除负值的这种重叠,如果我设置 horizo​​natal_chart.setDrawValueAboveBar(true) 那么正条将与正值重叠。这是代码:

private fun filterHorizontalBarData(myList: List<Response>?) {
try {

val brand = ArrayList<String>()
var index = 0f
var color_index = 0
val data = BarData()
val values_adapter = ArrayList<String>()

for (item in myList!!) {
if (item.kPI.equals("Value % Growth") || item.kPI.equals("Volume % Growth")) {
val kpiValue = ArrayList<BarEntry>()
kpiValue.add(BarEntry(index,item.kPIvalue.toFloat()))
brand.add(item.brand)

values_adapter.add(item.kPIvalue.toString())

val barDataSet = BarDataSet(kpiValue, item.brand)
if(color_index<7)
barDataSet.setColor(getColor(horizonatal_chart.context, getColorID(color_index)))
else
barDataSet.setColor(getColorID(color_index))
barDataSet.valueTextSize = 8f
// barDataSet.setDrawValues(false)
data.addDataSet(barDataSet)
index++
color_index++
}
}
// values_adapter.sortDescending()
// first_bar_values.adapter = AdapterValuesHorizontalBar(values_adapter)
setHorizontalChart(data, brand)
}catch (e: Exception){
e.printStackTrace()
}
}


private fun setHorizontalChart(data : BarData, brand: ArrayList<String>){

horizonatal_chart.setDrawBarShadow(false)
val description = Description()
description.text = ""
horizonatal_chart.description = description

horizonatal_chart.legend.setEnabled(false)
horizonatal_chart.setPinchZoom(false)

horizonatal_chart.setScaleEnabled(false)
horizonatal_chart.setDrawValueAboveBar(true)


//Display the axis on the left (contains the labels 1*, 2* and so on)
val xAxis = horizonatal_chart.getXAxis()
xAxis.setDrawGridLines(false)
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM)
xAxis.setEnabled(true)
xAxis.setDrawAxisLine(false)
xAxis.textColor = Color.parseColor("#a1a1a1")

xAxis.xOffset = 5f
val yLeft = horizonatal_chart.axisLeft

//Set the minimum and maximum bar lengths as per the values that they represent
yLeft.axisMaximum = 100f
yLeft.axisMinimum = 0f
yLeft.isEnabled = false
yLeft.setDrawZeroLine(true)
yLeft.granularity = 1f

//Now add the labels to be added on the vertical axis
xAxis.valueFormatter = IAxisValueFormatter { value, axis ->
if (value.toInt() < brand.size) {
brand.get(value.toInt())
} else {
"0"
}
}

val yRight = horizonatal_chart.axisRight
yRight.setDrawAxisLine(true)
yRight.setDrawGridLines(false)
yRight.isEnabled = false

//Set bar entries and add necessary formatting
horizonatal_chart.axisLeft.setAxisMinimum(data.yMin)

data.barWidth = 0.9f
// val myCustomChartRender = MyCustomChartRender(horizonatal_chart, horizonatal_chart.animator, horizonatal_chart.viewPortHandler)
// //Add animation to the graph
// horizonatal_chart.renderer = myCustomChartRender
horizonatal_chart.animateY(2000)
horizonatal_chart.data = data
horizonatal_chart.setTouchEnabled(false)
horizonatal_chart.invalidate()
}

请帮帮我!

最佳答案

问题似乎是您没有为 rightAxis 提供 minimummaximum 上限。

horizonatal_chart.axisRight.setAxisMinimum(-100)
horizonatal_chart.axisRight.setAxisMaximum(100)

引用:issue 提到了同样的问题并通过提供轴最小值和最大值解决

关于android - 将负值设置到水平条形图中条形的左侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59541099/

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