配置项如下
myChart.setOption({
grid: {
top: '12%',
bottom: '10%',
},
tooltip: {
position: 'right',
trigger: 'axis',
backgroundColor: '#fff',
borderColor: '#bdbdbd',
borderWidth: 1,
formatter: param => {
return '2222'
}
},
legend: {
data: ['funding amount', 'projects number'],
},
xAxis: [
{
type: 'category',
boundaryGap: true,
data: this.xAxisData,
axisLine: {
lineStyle: {
color: '#a5c7ce',
},
},
axisLabel: {
fontSize: 14,
fontWeight: 500,
color: '#a5c7ce',
interval: 0,
align: 'center',
},
splitLine: {
show: true,
lineStyle: {
color: '#a5c7ce',
type: 'dotted',
},
interval: 3,
},
axisTick: {
show: false,
},
},
],
yAxis: [
{
name: 'funding amount',
nameTextStyle: {
color: '#8e908b',
},
splitLine: {
show: false,
},
axisLine: {
lineStyle: {
color: '#a5c7ce',
},
},
axisTick: {
show: false,
alignWithLabel: true,
},
axisLabel: {
color: '#8e908b',
},
},
{
name: 'projects number',
nameTextStyle: {
color: '#8e908b',
},
splitLine: {
show: false,
},
axisLine: {
show: false,
},
axisTick: {
show: false,
alignWithLabel: true,
},
axisLabel: {
show: true,
color: '#8e908b',
},
},
],
series: [
{
name: 'projects number',
type: 'line',
showSymbol: false,
symbolSize: 2,
yAxisIndex: 1,
lineStyle: {
normal: {
color: '#2aafc7',
width: 2,
},
},
itemStyle: {
normal: {
color: '#2aafc7',
},
},
areaStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [{
offset: 0,
color: 'rgba(228, 243, 245, 0)', // 0% 处的颜色
}, {
offset: 1,
color: '#edeced', // 100% 处的颜色
}],
globalCoord: false,
},
},
data: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],
},
{
name: 'funding amount',
type: 'bar',
yAxisIndex: 0,
animation: false,
barWidth: 8,
itemStyle: {
normal: {
color: '#75bb00',
},
},
emphasis: {
itemStyle: {
color: '#54cce1',
},
},
data: [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]
},
],
})
let clickIndex = null
myChart.on('click', function (param) {
if (param.seriesIndex === 1) {
if (!_.isNull(clickIndex) && clickIndex !== param.dataIndex) {
myChart.dispatchAction({
type: 'downplay',
seriesIndex: 1,
dataIndex: clickIndex,
})
}
myChart.dispatchAction({
type: 'highlight',
seriesIndex: param.seriesIndex,
dataIndex: param.dataIndex,
})
clickIndex = param.dataIndex
}
});