英文:
Custom label on top of the Highchart using swift and highchart cocoapods
问题
I have Column chart in which i want to show rank of the chart on top of the column . i tried to show dataLabels but it only shows y value on the top. is that any way to add custom label on the top?
我有一个柱状图,我想在柱子的顶部显示排名。我尝试显示数据标签,但它只显示顶部的Y值。是否有办法在顶部添加自定义标签?
i tried to find answer on Highchart forums and Github forums for the same.please help me out with the code example.
我尝试在Highchart论坛和GitHub论坛上寻找答案,希望您能提供代码示例来帮助我。
i want to show custom value on top of the colomn.
我想在柱子的顶部显示自定义值。
let column = HIColumn()
column.data = arySerisModel[i].aryData
where 'arydata' is an array of float values.
我想要在柱子的中间显示另一个数组中的值:[1,1,2,3,3,4,5,6,6,7]
英文:
I have Column chart in which i want to show rank of the chart on top of the column . i tried to show dataLabels but it only shows y value on the top. is that any way to add custom label on the top?
i tried to find answer on Highchart forums and Github forums for the same.please help me out with the code example.
i want to show custom value on top of the colomn.
let column = HIColumn()
column.data = arySerisModel[i].aryData
where 'arydata' is array of float values.
i have another array = [1,1,2,3,3,4,5,6,6,7]
which i want to show on middle of column.
答案1
得分: 0
你可以使用dataLabels.format
属性或dataLabels.formatter()
回调函数来设置自定义标签文本。
plotOptions: {
series: {
dataLabels: {
enabled: true,
format: '自定义标签'
}
}
}
在Swift中实现这个功能会像这样:
let options = HIOptions()
let plotOptions = HIPlotOptions()
plotOptions.series = HISeries()
let dataLabels = HIDataLabels()
dataLabels.enabled = true
dataLabels.formatter = HIFunction(jsFunction: "function() { const point = this.point, customLabel = point.customLabel; return `${customLabel ? customLabel : point.y}`; }")
plotOptions.series.dataLabels = [dataLabels]
options.plotOptions = plotOptions
let series = HISeries()
series.data = [
["y": 29.9],
["y": 71.5, "customLabel": "自定义 A"],
["y": 129.2, "customLabel": "自定义 B"],
["y": 144]
]
options.series = [series]
演示: https://jsfiddle.net/BlackLabel/afub368p/
文档: https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting
API: https://api.highcharts.com/highcharts/series.pie.dataLabels.format
英文:
You can use the dataLabels.format
property or the dataLabels.formatter()
callback function to set custom label text.
plotOptions: {
series: {
dataLabels: {
enabled: true,
format: 'Custom label'
}
}
},
Implementing this in Swift will look like this:
let options = HIOptions()
let plotOptions = HIPlotOptions()
plotOptions.series = HISeries()
let dataLabels = HIDataLabels()
dataLabels.enabled = true
dataLabels.formatter = HIFunction(jsFunction: "function() { const point = this.point, customLabel = point.customLabel; return `${customLabel ? customLabel : point.y}`; }")
plotOptions.series.dataLabels = [dataLabels]
options.plotOptions = plotOptions
let series = HISeries()
series.data = [
["y": 29.9],
["y": 71.5, "customLabel": "Custom A"],
["y": 129.2, "customLabel": "Custom B"],
["y": 144]
]
options.series = [series]
Demo: https://jsfiddle.net/BlackLabel/afub368p/ <br/>
Docs: https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting <br/>
API: https://api.highcharts.com/highcharts/series.pie.dataLabels.format
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论