配置项如下
option = {
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
data: [820, 932, 901, 934, 1290, 1330, 1320],
type: 'line'
},
{
type: 'custom',
renderItem: renderItem,
/*xAxisIndex: 1,*/
data: [[200, 20, 300, 40], [120, 150, 50, 60], [70, 80, 90, 100]]
}
]
};
function renderItem(params, api) {
var points = [[api.value(0), api.value(1)],[api.value(2), api.value(3)]];
console.log(points);
return {
type: 'polygon',
// type: 'line',
// shape: {
// x1: api.value(0),
// y1: api.value(1),
// x2: api.value(2),
// y2: api.value(3),
// },
shape: {
points: echarts.graphic.clipPointsByRect(
points,
{
x: params.coordSys.x,
y: params.coordSys.y,
width: params.coordSys.width,
height: params.coordSys.height
}
)
},
/*style: api.style()*/
style: {
stroke: 'black',
fill: 'black'
}
}
}