Bar

柱状图。

使用

  1. <m-bar id="myBar" width="600" height="300" data="{
  2. labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
  3. datasets: [{
  4. label: '# of Votes',
  5. data: [12, 19, 3, 5, 2, 3],
  6. backgroundColor: [
  7. 'rgba(255, 99, 132, 0.2)',
  8. 'rgba(54, 162, 235, 0.2)',
  9. 'rgba(255, 206, 86, 0.2)',
  10. 'rgba(75, 192, 192, 0.2)',
  11. 'rgba(153, 102, 255, 0.2)',
  12. 'rgba(255, 159, 64, 0.2)'
  13. ],
  14. borderColor: [
  15. 'rgba(255,99,132,1)',
  16. 'rgba(54, 162, 235, 1)',
  17. 'rgba(255, 206, 86, 1)',
  18. 'rgba(75, 192, 192, 1)',
  19. 'rgba(153, 102, 255, 1)',
  20. 'rgba(255, 159, 64, 1)'
  21. ],
  22. borderWidth: 1
  23. }]
  24. }"
  25. options="{
  26. legend: {
  27. display: false
  28. },
  29. scales: {
  30. yAxes: [{
  31. ticks: {
  32. beginAtZero: true
  33. }
  34. }]
  35. }
  36. }"></m-bar>

更新图表

  1. //获取该元素
  2. var chart = document.querySelector('#myBar')
  3. //更改图表的数据
  4. chart.props.data.datasets.forEach(dataset => {
  5. dataset.data.forEach((item, index) => {
  6. dataset.data[index] = Math.random() * 100
  7. })
  8. })
  9. //更新图表视图
  10. chart.update()

API

Props

  1. {
  2. data: object,
  3. options: object,
  4. width: number,
  5. height: number,
  6. horizontal?: string
  7. }