基础折线图

image.png

  1. import React, { useEffect, useRef } from 'react'
  2. import * as echarts from 'echarts'
  3. import { createEchartsOptions } from '../shared/create-echart-options'
  4. import { px } from '../shared/px'
  5. export const Chart3 = () => {
  6. const divRef = useRef(null)
  7. useEffect(() => {
  8. var myChart = echarts.init(divRef.current)
  9. myChart.setOption(
  10. createEchartsOptions({
  11. legend: {
  12. bottom: px(10),
  13. textStyle: { color: 'white' },
  14. itemWidth: px(30),
  15. itemHeight: px(16),
  16. },
  17. grid: {
  18. x: px(20),
  19. x2: px(20),
  20. y: px(20),
  21. y2: px(70),
  22. containLabel: true,
  23. },
  24. xAxis: {
  25. type: 'category',
  26. boundaryGap: false,
  27. data: [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018],
  28. splitLine: { show: true, lineStyle: { color: '#073E78' } },
  29. axisTick: { show: false },
  30. axisLine: { show: false },
  31. },
  32. yAxis: {
  33. type: 'value',
  34. splitLine: { lineStyle: { color: '#073E78' } },
  35. axisLabel: {
  36. formatter(val) {
  37. return val * 100 + '%'
  38. },
  39. },
  40. },
  41. series: [
  42. {
  43. name: '抢劫',
  44. type: 'line',
  45. data: [
  46. 0.01, 0.32, 0.13, 0.34, 0.25, 0.16, 0.27, 0.38, 0.49,
  47. ].reverse(),
  48. },
  49. {
  50. name: '醉驾',
  51. type: 'line',
  52. data: [
  53. 0.22, 0.13, 0.34, 0.45, 0.36, 0.27, 0.18, 0.29, 0.11,
  54. ].reverse(),
  55. },
  56. {
  57. name: '盗窃',
  58. type: 'line',
  59. data: [
  60. 0.13, 0.04, 0.25, 0.16, 0.27, 0.38, 0.29, 0.1, 0.11,
  61. ].reverse(),
  62. },
  63. {
  64. name: '故意杀人',
  65. type: 'line',
  66. data: [
  67. 0.04, 0.15, 0.06, 0.27, 0.08, 0.39, 0.1, 0.21, 0.32,
  68. ].reverse(),
  69. },
  70. {
  71. name: '故意伤人',
  72. type: 'line',
  73. data: [
  74. 0.05, 0.26, 0.17, 0.08, 0.19, 0.1, 0.31, 0.22, 0.43,
  75. ].reverse(),
  76. },
  77. ].map((obj) => ({ // 设置转折点为圆点
  78. ...obj,
  79. symbol: 'circle',
  80. symbolSize: px(12),
  81. lineStyle: { width: px(2) },
  82. })),
  83. })
  84. )
  85. }, [])
  86. return (
  87. <div className="bordered 发案趋势">
  88. <h2>发案趋势分析</h2>
  89. <div ref={divRef} className="chart" />
  90. </div>
  91. )
  92. }

基础面积图

image.png

  1. import React, { useEffect, useRef } from 'react'
  2. import * as echarts from 'echarts'
  3. import { createEchartsOptions } from '../shared/create-echart-options'
  4. import { px } from '../shared/px'
  5. export const Chart4 = () => {
  6. const divRef = useRef(null)
  7. useEffect(() => {
  8. var myChart = echarts.init(divRef.current)
  9. myChart.setOption(
  10. createEchartsOptions({
  11. xAxis: {
  12. type: 'category',
  13. boundaryGap: false,
  14. data: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24],
  15. splitLine: { show: true, lineStyle: { color: '#073E78' } },
  16. axisTick: { show: false },
  17. axisLine: { show: false },
  18. },
  19. yAxis: {
  20. type: 'value',
  21. splitLine: { lineStyle: { color: '#073E78' } },
  22. axisLabel: {
  23. formatter(val) {
  24. return val * 100 + '%'
  25. },
  26. },
  27. },
  28. series: [
  29. {
  30. name: '故意伤人',
  31. type: 'line',
  32. data: [
  33. 0.15, 0.13, 0.11, 0.13, 0.14, 0.15, 0.18, 0.24, 0.27, 0.26, 0.25,
  34. 0.21, 0.14,
  35. ],
  36. symbol: 'circle',
  37. symbolSize: px(12),
  38. lineStyle: { width: px(2) },
  39. // 面积颜色渐变
  40. areaStyle: {
  41. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  42. {
  43. offset: 0,
  44. color: '#414a9f',
  45. },
  46. {
  47. offset: 1,
  48. color: '#1b1d52',
  49. },
  50. ]),
  51. },
  52. },
  53. ],
  54. })
  55. )
  56. }, [])
  57. return (
  58. <div className="bordered 案发时段">
  59. <h2>案发时段分析</h2>
  60. <div ref={divRef} className="chart" />
  61. </div>
  62. )
  63. }