https://echarts.apache.org/examples/zh/editor.html?c=line-simple

js按需加载

  1. import * as echarts from 'echarts/core';
  2. import { GridComponent } from 'echarts/components';
  3. import { LineChart } from 'echarts/charts';
  4. import { UniversalTransition } from 'echarts/features';
  5. import { CanvasRenderer } from 'echarts/renderers';
  6. echarts.use([GridComponent, LineChart, CanvasRenderer, UniversalTransition]);
  7. var chartDom = document.getElementById('main');
  8. var myChart = echarts.init(chartDom);
  9. var option;
  10. option = {
  11. xAxis: {
  12. type: 'category',
  13. boundaryGap: false,
  14. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  15. },
  16. yAxis: {
  17. type: 'value'
  18. },
  19. series: [
  20. {
  21. data: [150, 230, 224, 218, 335, 517, 260],
  22. type: 'line',
  23. symbol: 'none' // 去掉折线上面的小圆点
  24. }
  25. ]
  26. };
  27. option && myChart.setOption(option);

自定义折线图

  • 折线图颜色渐变
  • 折线图宽度

image.png

  1. option = {
  2. xAxis: {
  3. type: 'category',
  4. boundaryGap: false,
  5. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  6. },
  7. yAxis: {
  8. type: 'value'
  9. },
  10. series: [
  11. {
  12. data: [150, 230, 224, 218, 335, 517, 260],
  13. type: 'line',
  14. symbol: 'none', // 去掉折线上面的小圆点
  15. itemStyle: {
  16. normal: {
  17. color: '#fff',
  18. fontSize: 14,
  19. lineStyle: {
  20. width: 1.5, //折线宽度
  21. //折线颜色渐变
  22. color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
  23. {
  24. offset: 0,
  25. color: 'rgba(45,105,249,1)'
  26. },
  27. {
  28. offset: 1,
  29. color: 'rgba(89,205,253,1)'
  30. }
  31. ])
  32. }
  33. },
  34. emphasis: {
  35. //鼠标经过时折点小圆圈样式
  36. borderColor: 'rgba(0,196,132,0.2)',
  37. borderWidth: 4
  38. }
  39. }
  40. }
  41. ]
  42. };