如何在echarts条形图中手动强调系列?
How to manually apply emphasis on series in echarts bar-graph?
我有一个包含一系列数据的 echarts 条形图。单击某个栏时,会对其应用强调。有没有办法以编程方式 select 条形图中的一个系列来强调图表加载的时间?
条形图的选项代码:
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 有两种动作相反的方法:
action.highlight
— 将强调样式设置为数据点。
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>
- 教程:https://echarts.apache.org/en/tutorial.html)
- 组件参考:https://echarts.apache.org/en/option.html
- 常见问题https://echarts.apache.org/en/faq.html
- API参考https://echarts.apache.org/en/api.html
- 地球参考 https://echarts.apache.org/en/option-gl.html
- 很棒的 Echarts https://github.com/ecomfe/awesome-echarts
- 关于 Github https://github.com/apache/incubator-echarts/issues?q=
的问题
- Github要点https://gist.github.com/search?l=JavaScript&o=desc&q=echarts&s=updated
- 通过 JSFiddle 搜索 https://www.google.com/search?q=site%3Ahttps%3A%2F%2Fjsfiddle.net+Echarts
- 通过 Codepen 搜索 https://www.google.com/search?q=site%3Ahttps%3A%2F%2Fcodepen.io+Echarts
- Echarts 图库https://gallery.echartsjs.com/explore.html#sort=rank~timeframe=all~author=all
我有一个包含一系列数据的 echarts 条形图。单击某个栏时,会对其应用强调。有没有办法以编程方式 select 条形图中的一个系列来强调图表加载的时间?
条形图的选项代码:
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 有两种动作相反的方法:
action.highlight
— 将强调样式设置为数据点。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>
- 教程:https://echarts.apache.org/en/tutorial.html)
- 组件参考:https://echarts.apache.org/en/option.html
- 常见问题https://echarts.apache.org/en/faq.html
- API参考https://echarts.apache.org/en/api.html
- 地球参考 https://echarts.apache.org/en/option-gl.html
- 很棒的 Echarts https://github.com/ecomfe/awesome-echarts
- 关于 Github https://github.com/apache/incubator-echarts/issues?q= 的问题
- Github要点https://gist.github.com/search?l=JavaScript&o=desc&q=echarts&s=updated
- 通过 JSFiddle 搜索 https://www.google.com/search?q=site%3Ahttps%3A%2F%2Fjsfiddle.net+Echarts
- 通过 Codepen 搜索 https://www.google.com/search?q=site%3Ahttps%3A%2F%2Fcodepen.io+Echarts
- Echarts 图库https://gallery.echartsjs.com/explore.html#sort=rank~timeframe=all~author=all