<vega-bar-chart></vega-bar-chart>
const weeklyData = [
{ x: 'Mon', y: 1167 },
{ x: 'Tue', y: 1492 },
{ x: 'Wed', y: 1782 },
{ x: 'Thu', y: 1253 },
{ x: 'Fri', y: 1702 },
{ x: 'Sat', y: 1288 },
{ x: 'Sun', y: 1015 },
];
const barChart = document.querySelector('vega-bar-chart');
barChart.options = {
layout: {
width: 500,
height: 300,
},
dataSource: weeklyData,
legends: ['Vega'],
};<vega-bar-chart></vega-bar-chart>
const weeklyData = [
{ x: 'Mon', y: 1167 },
{ x: 'Tue', y: 1492 },
{ x: 'Wed', y: 1782 },
{ x: 'Thu', y: 1253 },
{ x: 'Fri', y: 1702 },
{ x: 'Sat', y: 1288 },
{ x: 'Sun', y: 1015 },
];
const barChart = document.querySelector('vega-bar-chart');
barChart.options = {
layout: {
width: 500,
height: 300,
},
dataSource: weeklyData,
legends: ['Vega'],
direction: 'horizontal',
};Bar charts are simple charts designed for showing categorical data using rectangular bars on an x-y axis. In a simple bar chart, the height of the bar indicates the y value. Bar charts have the advantage of being intuitively understandable by most users. Complex data can be represented side-by-side.
| Name | Description | Default | |
|---|---|---|---|
| options* | data source required |
||
| Options | |||
| layout | The chart layout{width:number, height:number, margin:{top:number, left:number, right:number, bottom:number}} |
- | - |
| legends | The chart legends, required if legends need to be displayedstring[] |
- | - |
| dataSource* | The chart data source{x:number, y:number} |
- | - |
| colors | The chart line colorvega design backgroud color token array |
bg-accent1-primary bg-accent2-primary bg-accent3-primary bg-accent4-primary bg-accent5-primary bg-accent6-primary bg-accent7-primary |
|
| xAxis | The chart x axis setting{ labelFormatter: text=> text } |
||
| yAxis | The chart y axis setting{labelFormatter: text=> text} |
||
| direction | The direction of the layout for the bar chart vertical horizontal |
vertical |
x and y axes are switched).