如何手动将重点放在echarts条形图中的系列上? [英] How to manually apply emphasis on series in echarts bar-graph?
本文介绍了如何手动将重点放在echarts条形图中的系列上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有一系列数据的echarts条形图.单击条形时,将对其施加强调.有没有一种方法可以通过编程方式选择条形图中的系列之一,以在图形加载时重点关注?
I have a echarts bar graph with series of data. When a bar is clicked, emphasis is applied on it. Is there a way to programmatically select one of the series in the bar-graph to apply emphasis on when the graph loads?
条形图的选项代码:
options = {
markPoint: { data: ['Q1'] },
color: ['#3398DB'],
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [
{
type: 'category',
data: ['Q1', 'Q2', 'Q3', 'Q4'],
axisTick: {
alignWithLabel: true,
}
}
],
yAxis: [{
type: 'value'
}],
series: [{
name: 'Counters',
type: 'bar',
barWidth: '50%',
data: [3,8,12,5],
itemStyle: {
//highlight
emphasis: {
barBorderColor: 'red',
barBorderWidth: 2
}
}
}]
};
谢谢.
推荐答案
是的,很简单.Echarts API有两种方法具有相反的作用:
Yes, it's easy. The Echarts API has two methods with opposite actions:
-
action.highlight
—将强调样式设置为dataPoint. -
action.downplay
—取消突出显示.
一个小例子:
var myChart = echarts.init(document.getElementById('main'));
var chartData = [5, 20, 36, 10, 10, 20];
var option = {
tooltip: {},
legend: {
data: ['Label']
},
xAxis: {
data: ["Category1", "Category2", "Category3", "Category4", "Category5", "Category6"]
},
yAxis: {},
series: [{
name: 'Series',
type: 'bar',
data: chartData,
emphasis: {
itemStyle: {
color: 'blue'
}
},
}]
};
myChart.setOption(option);
// Current selected dataPoint
var selectedDataPoint = null;
// Each eteration set another type of
setInterval(() => {
var randomDataPoint = Math.floor(Math.random() * Math.floor(chartData.length));
myChart.dispatchAction({ type: 'highlight', dataIndex: randomDataPoint })
}, 800)
<script src="https://cdn.jsdelivr.net/npm/echarts@4.8.0/dist/echarts.min.js"></script>
<div id="main" style="width: 600px;height:400px;"></div>
这篇关于如何手动将重点放在echarts条形图中的系列上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文