ike-yu-byte commented on issue #17512:
URL: https://github.com/apache/echarts/issues/17512#issuecomment-1218102387
`renderItem(params, api) {
// api.value: 得到给定维度数据值
// api.coord:将数据映射到坐标系上
let categoryIndex = api.value(0)
let start = api.coord([categoryIndex, api.value(1)])
let end = api.coord([categoryIndex, api.value(2)])
let width = api.size([0, api.value(2)])[0] * 0.8
const num = api.value(4) // 每个系列柱子数
const currentIndex = api.value(3)
const isOdd = num % 2 === 0
const midN = isOdd ? num / 2 : (num + 1) / 2
let rect = ''
// width = width / num
width = this.barWidth ? this.barWidth : (width / num)
let rectX = start[0] - width / 2
const FIXED_WIDTH = 5 // 柱子间距
// 数据处理,结构为 { itemStyle: { normal: { color: 'lightgreen' } },
name: '2011', value: [0, 0, 150, 2, 5] }
// 其中value
分为五个维度,分别为{系列项}(从0开始)、y轴起始值(均为0)、实际值、同系列中索引值(从1开始)、同系列数据项总数
if (num > 1) {
if (isOdd) {
if (currentIndex <= midN) {
// 中位数左侧
rectX = start[0] - width / 2 - width / 2 +
(currentIndex - midN) * width - FIXED_WIDTH * (midN + 1 - currentIndex)
} else {
// 中位数右侧
rectX = start[0] - width / 2 + width / 2 +
(currentIndex - midN - 1) * width + FIXED_WIDTH * (currentIndex - midN)
}
} else {
rectX = start[0] - width / 2 + (currentIndex - midN) *
(width + FIXED_WIDTH)
}
}
rect = {
type: 'rect',
transition: ['shape'],
shape: echarts.graphic.clipRectByRect(
{ x: rectX, y: end[1], width: width, height: start[1] -
end[1] },
{
x: params.coordSys.x,
y: params.coordSys.y,
width: params.coordSys.width,
height: params.coordSys.height
}
),
style: api.style()
}
return rect
}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]