折线区域图

  1. option = {
  2. title: {
  3. text: 'Stacked Line'
  4. },
  5. tooltip: {
  6. trigger: 'axis'
  7. },
  8. grid: {
  9. left: '3%',
  10. right: '4%',
  11. bottom: '3%',
  12. containLabel: true
  13. },
  14. toolbox: {
  15. feature: {
  16. saveAsImage: {}
  17. }
  18. },
  19. xAxis: {
  20. type: 'category',
  21. boundaryGap: false,
  22. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
  23. // 刻度尺对应文案设置
  24. axisLabel: {
  25. // @ts-ignore
  26. margin: 15,
  27. },
  28. // 刻度尺长度设置
  29. axisTick: {
  30. length: 10,
  31. lineStyle: {
  32. type: 'soild',
  33. },
  34. }
  35. },
  36. yAxis: {
  37. type: 'value',
  38. splitLine: { // 刻度虚线
  39. show: true,
  40. lineStyle: {
  41. color: "#085387" // "rgba(0,0,0, 0.1)"
  42. }
  43. },
  44. },
  45. series: [
  46. {
  47. type: 'line',
  48. stack: 'Total',
  49. areaStyle: {
  50. normal: {
  51. color: 'rgba(52, 144, 255, 0.2)' // 区域的颜色
  52. }
  53. },
  54. lineStyle: { // 线条的宽度
  55. width: 1
  56. },
  57. showSymbol: true, // 折线上的点位显示
  58. itemStyle:{
  59. normal: {
  60. color: '#3490ff', // 改变点的颜色
  61. lineStyle: {
  62. color: "#3490ff" // 改变线条的颜色
  63. }
  64. }
  65. },
  66. smooth: true,
  67. data: [120, 132, 101, 134, 90, 230, 210]
  68. }
  69. ]
  70. };

image.png

  1. import React from 'react';
  2. import * as echarts from 'echarts';
  3. interface IProps {
  4. height?: number;
  5. xAxisData: string[];
  6. seriesData: number[];
  7. }
  8. (function() {
  9. const throttle = function(type, name, obj) {
  10. obj = obj || window;
  11. var running = false;
  12. var func = function() {
  13. if (running) { return; }
  14. running = true;
  15. requestAnimationFrame(function() {
  16. obj.dispatchEvent(new CustomEvent(name));
  17. running = false;
  18. });
  19. };
  20. obj.addEventListener(type, func);
  21. };
  22. /* init - you can init any event */
  23. throttle("resize", "optimizedResize");
  24. })();
  25. export class EchartsLine extends React.Component<IProps> {
  26. echartsRef: HTMLDivElement | null = null;
  27. componentDidMount() {
  28. const myChart = echarts.init((this.echartsRef as HTMLDivElement));
  29. const option = {
  30. tooltip: {
  31. trigger: 'axis'
  32. },
  33. grid: {
  34. left: '3%',
  35. right: '4%',
  36. bottom: '3%',
  37. containLabel: true
  38. },
  39. toolbox: {
  40. feature: {
  41. saveAsImage: {}
  42. }
  43. },
  44. xAxis: {
  45. type: 'category',
  46. boundaryGap: false,
  47. data: this.props.xAxisData || ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  48. },
  49. yAxis: {
  50. type: 'value'
  51. },
  52. series: [
  53. {
  54. type: 'line',
  55. stack: 'Total',
  56. areaStyle: {
  57. normal: {
  58. color: 'rgba(52, 144, 255, 0.2)'
  59. }
  60. },
  61. itemStyle: {
  62. normal: {
  63. color: '#3490ff',
  64. lineStyle: {
  65. color: '#3490ff'
  66. }
  67. }
  68. },
  69. smooth: true,
  70. data: this.props.seriesData || [120, 132, 101, 134, 90, 230, 210]
  71. }
  72. ]
  73. };
  74. myChart.setOption(option);
  75. window.addEventListener("optimizedResize", () => {
  76. this.echartsPie.resize();
  77. });
  78. }
  79. render() {
  80. return <div style={{ height: this.props.height || 300 }} ref={(ref) => {
  81. this.echartsRef = ref;
  82. }} className='echarts-line' />
  83. }
  84. }