|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | + <head> |
| 4 | + <meta charset="UTF-8" /> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 6 | + <meta http-equiv="X-UA-Compatible" content="ie=edge" /> |
| 7 | + <title>Live Needle Gauge</title> |
| 8 | + |
| 9 | + <link href="../../assets/styles.css" rel="stylesheet" /> |
| 10 | + |
| 11 | + <style> |
| 12 | + |
| 13 | + #chart { |
| 14 | + padding: 0; |
| 15 | + max-width: 560px; |
| 16 | + margin: 35px auto; |
| 17 | + } |
| 18 | + |
| 19 | + </style> |
| 20 | + |
| 21 | + |
| 22 | + <script src="https://cdn.jsdelivr.net/npm/react@17.0.2/umd/react.production.min.js"></script> |
| 23 | + <script src="https://cdn.jsdelivr.net/npm/react-dom@17.0.2/umd/react-dom.production.min.js"></script> |
| 24 | + <script src="https://cdn.jsdelivr.net/npm/prop-types@15.8.1/prop-types.min.js"></script> |
| 25 | + <script src="https://cdn.jsdelivr.net/npm/babel-core@5.8.34/browser.min.js"></script> |
| 26 | + <script src="../../../dist/apexcharts.js"></script> |
| 27 | + <script src="https://cdn.jsdelivr.net/npm/react-apexcharts@1.7.0/dist/react-apexcharts.iife.min.js"></script> |
| 28 | + |
| 29 | + |
| 30 | + <script> |
| 31 | + // Replace Math.random() with a pseudo-random number generator to get reproducible results in e2e tests |
| 32 | + // Based on https://gist.github.com/blixt/f17b47c62508be59987b |
| 33 | + var _seed = 42 |
| 34 | + Math.random = function () { |
| 35 | + _seed = (_seed * 16807) % 2147483647 |
| 36 | + return (_seed - 1) / 2147483646 |
| 37 | + } |
| 38 | + </script> |
| 39 | + |
| 40 | + |
| 41 | + </head> |
| 42 | + |
| 43 | + <body> |
| 44 | + |
| 45 | + <div id="app"></div> |
| 46 | + |
| 47 | + <div id="html"><div id="chart"> |
| 48 | + <ReactApexChart options={state.options} series={state.series} type="gauge" height={360} /> |
| 49 | +</div></div> |
| 50 | + |
| 51 | + <script type="text/babel"> |
| 52 | + const ApexChart = () => { |
| 53 | + const [state, setState] = React.useState({ |
| 54 | + |
| 55 | + series: [86], |
| 56 | + options: { |
| 57 | + chart: { |
| 58 | + height: 360, |
| 59 | + type: 'gauge', |
| 60 | + animations: { |
| 61 | + enabled: true, |
| 62 | + dynamicAnimation: { enabled: true, speed: 800 }, |
| 63 | + }, |
| 64 | + }, |
| 65 | + colors: ['#00A86F'], |
| 66 | + plotOptions: { |
| 67 | + radialBar: { |
| 68 | + shape: 'needle', |
| 69 | + startAngle: -90, |
| 70 | + endAngle: 90, |
| 71 | + min: 0, |
| 72 | + max: 100, |
| 73 | + ticks: { |
| 74 | + show: true, |
| 75 | + major: { |
| 76 | + count: 11, |
| 77 | + length: 0, |
| 78 | + width: 0, |
| 79 | + color: 'transparent', |
| 80 | + placement: 'outside', |
| 81 | + }, |
| 82 | + minor: { |
| 83 | + count: 0, |
| 84 | + length: 0, |
| 85 | + width: 0, |
| 86 | + color: 'transparent', |
| 87 | + }, |
| 88 | + labels: { |
| 89 | + show: true, |
| 90 | + offset: 25, |
| 91 | + fontSize: '12px', |
| 92 | + fontWeight: 500, |
| 93 | + color: '#0F172A', |
| 94 | + formatter: function (v) { |
| 95 | + return v + '%' |
| 96 | + }, |
| 97 | + }, |
| 98 | + }, |
| 99 | + needle: { |
| 100 | + color: '#1E293B', |
| 101 | + length: '85%', |
| 102 | + baseWidth: 10, |
| 103 | + tipWidth: 1, |
| 104 | + showValueArc: true, |
| 105 | + }, |
| 106 | + track: { |
| 107 | + show: true, |
| 108 | + background: '#ddd', |
| 109 | + strokeWidth: '100%', |
| 110 | + margin: 0, |
| 111 | + }, |
| 112 | + hollow: { |
| 113 | + margin: 0, |
| 114 | + size: '70%', |
| 115 | + background: 'transparent', |
| 116 | + }, |
| 117 | + dataLabels: { |
| 118 | + name: { show: false }, |
| 119 | + value: { |
| 120 | + offsetY: 20, |
| 121 | + fontSize: '16px', |
| 122 | + fontWeight: 700, |
| 123 | + color: '#0F172A', |
| 124 | + formatter: function (val) { |
| 125 | + return val + '%' |
| 126 | + }, |
| 127 | + }, |
| 128 | + }, |
| 129 | + }, |
| 130 | + }, |
| 131 | + stroke: { |
| 132 | + lineCap: 'butt', |
| 133 | + }, |
| 134 | + labels: ['Progress'], |
| 135 | + }, |
| 136 | + |
| 137 | + |
| 138 | + }); |
| 139 | + |
| 140 | + |
| 141 | + useEffect(() => { |
| 142 | + const id = window.setInterval(() => { |
| 143 | + setState((s) => ({ ...s, series: [Math.floor(Math.random() * 101)] })) |
| 144 | + }, 2000) |
| 145 | + return () => window.clearInterval(id) |
| 146 | + }, []) |
| 147 | + |
| 148 | + |
| 149 | + return ( |
| 150 | + <div> |
| 151 | + <div id="chart"> |
| 152 | + <ReactApexChart options={state.options} series={state.series} type="gauge" height={360} /> |
| 153 | + </div> |
| 154 | + <div id="html-dist"></div> |
| 155 | + </div> |
| 156 | + ); |
| 157 | + } |
| 158 | + |
| 159 | + const domContainer = document.querySelector('#app'); |
| 160 | + ReactDOM.render(<ApexChart />, domContainer); |
| 161 | + </script> |
| 162 | + |
| 163 | + |
| 164 | + </body> |
| 165 | +</html> |
0 commit comments