echarts折線圖背景漸變以及常用配置項

2022-4-6    前端達人


  1. let myChart = this.$echarts.init(document.getElementById('plant-charts'));
  2. // 繪制圖表
  3. myChart.setOption({
  4. tooltip: {
  5. formatter: '{c}' //設置單位
  6. },
  7. //圖例樣式
  8. legend: {
  9. data: ['寬帶情況', '數據量'],
  10. textStyle: {//圖例文字的樣式
  11. color: '#fff',
  12. fontSize: 12,
  13. padding: [0, 20, 0, 0]
  14. }
  15. },
  16. grid: { //設置圖標距離父級div的間距
  17. top: "10",
  18. left: "0",
  19. right: "15",
  20. bottom: "10",
  21. containLabel: true
  22. },
  23. xAxis: {
  24. type: 'category',
  25. boundaryGap: false,
  26. data: ['2015','2016','2017','2018','2019','2020','2021'],
  27. axisLabel: {
  28. interval: '0', //類目軸(category)中用數值表示顯示間隔,0為顯示所有,1為隔一個顯示一個,以此類推
  29. textStyle: { //文字樣式
  30. color: '#62799C',
  31. fontSize: '12'
  32. },
  33. },
  34. axisTick: { //y軸刻度線不顯示
  35. show: false
  36. },
  37. },
  38. yAxis: {
  39. type: 'value',
  40. //show: false,
  41. axisLabel: {
  42. textStyle: { //文字樣式
  43. color: '#62799C',
  44. fontSize: '12'
  45. },
  46. },
  47. // 控制網格線
  48. splitLine: {
  49. // 改變軸線顏色
  50. lineStyle: {
  51. color: '#2a2a2d'
  52. }
  53. },
  54. axisTick: { //y軸刻度線
  55. show: false
  56. },
  57. },
  58. series: [{
  59. data: [5000,6000,7000,4400,3200,4500,6800],
  60. type: 'line',
  61. itemStyle: {
  62. normal: {
  63. color: 'rgba(62,139,222,1)'//線顏色
  64. }
  65. },
  66. areaStyle: {
  67. normal: {
  68. color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{ //折線圖顏色漸變
  69. offset: 0,
  70. color: 'rgba(62,139,222,0.6)'
  71. }, {
  72. offset: 1,
  73. color: 'rgba(62,139,222,0.01)'
  74. }])
  75. }
  76. },
  77. }]
  78. });

分享本文至:

日歷

鏈接

個人資料

藍藍設計的小編 http://www.bouu.cn

存檔