Skip to content
ECharts

Bar Chart

Category bar chart with axis tooltip and styled bars.

By EZ4Code Team
echartsbar

Code

const chart = echarts.init(document.getElementById('chart'));
chart.setOption({
  title: { text: 'Monthly Sales', left: 'center' },
  tooltip: { trigger: 'axis' },
  xAxis: {
    type: 'category',
    data: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
  },
  yAxis: { type: 'value', name: 'k$' },
  series: [{
    name: 'Sales',
    type: 'bar',
    data: [120, 200, 150, 80, 70, 110],
    itemStyle: { color: '#5470c6', borderRadius: [4, 4, 0, 0] },
    barWidth: '60%',
    label: { show: true, position: 'top' }
  }]
});

Explanation

Initialize echarts on a DOM element and pass an option object to setOption. The bar series maps category xAxis data to value yAxis via the data array. itemStyle.borderRadius rounds the top corners and label.show displays the value above each bar; trigger:'axis' shows all series values on hover.

More ECharts Snippets