|
| 1 | +import {memo} from 'react'; |
| 2 | +import Chart from 'react-apexcharts'; |
| 3 | + |
| 4 | +const ChartBar = memo(({ series, categories, height, width="100%", title }) => { |
| 5 | + |
| 6 | + console.log(series,categories); |
| 7 | + var options = { |
| 8 | + chart: { |
| 9 | + type: 'bar', |
| 10 | + height: height, |
| 11 | + foreColor: '#9e9b9a', |
| 12 | + zoom: { |
| 13 | + enabled: false |
| 14 | + }, |
| 15 | + animations: { |
| 16 | + enabled: false, |
| 17 | + }, |
| 18 | + labels: JSON.parse(categories), |
| 19 | + dynamicAnimation : |
| 20 | + { |
| 21 | + enabled: true, |
| 22 | + }, |
| 23 | + toolbar: { |
| 24 | + show: false, |
| 25 | + } |
| 26 | + }, |
| 27 | + plotOptions: { |
| 28 | + bar: { |
| 29 | + borderRadius: 4, |
| 30 | + horizontal: true, |
| 31 | + } |
| 32 | + }, |
| 33 | + xaxis: { |
| 34 | + categories: JSON.parse(categories), |
| 35 | + labels : { |
| 36 | + formatter: function(val, index) { |
| 37 | + |
| 38 | + if(val === 0) return '0'; |
| 39 | + if(val < 1000) return parseFloat(val).toFixed(0); |
| 40 | + |
| 41 | + var k = 1000, |
| 42 | + sizes = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'], |
| 43 | + i = Math.floor(Math.log(val) / Math.log(k)); |
| 44 | + return parseFloat((val / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]; |
| 45 | + |
| 46 | + }, |
| 47 | + style: { |
| 48 | + fontSize: '11px', |
| 49 | + fontFamily: 'Lato', |
| 50 | + }, |
| 51 | + |
| 52 | + }, |
| 53 | + }, |
| 54 | + grid: { |
| 55 | + show: false, |
| 56 | + yaxis: { |
| 57 | + lines: { |
| 58 | + show: false |
| 59 | + } |
| 60 | + }, |
| 61 | + xaxis: { |
| 62 | + lines: { |
| 63 | + show: false |
| 64 | + }, |
| 65 | + } |
| 66 | + }, |
| 67 | + tooltip: { |
| 68 | + theme: "dark", |
| 69 | + }, |
| 70 | + dataLabels: { |
| 71 | + enabled: true, |
| 72 | + style: { |
| 73 | + fontSize: '11px', |
| 74 | + fontWeight: 'bold', |
| 75 | + fontFamily: 'Lato', |
| 76 | + }, |
| 77 | + formatter: function(val, index) { |
| 78 | + |
| 79 | + if(val === 0) return '0'; |
| 80 | + if(val < 1000) return parseFloat(val).toFixed(0); |
| 81 | + |
| 82 | + var k = 1000, |
| 83 | + sizes = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'], |
| 84 | + i = Math.floor(Math.log(val) / Math.log(k)); |
| 85 | + return parseFloat((val / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]; |
| 86 | + |
| 87 | + }, |
| 88 | + }, |
| 89 | + |
| 90 | + }; |
| 91 | + |
| 92 | + |
| 93 | + return ( |
| 94 | + <div> |
| 95 | + <Chart options={options} series={JSON.parse(series)} type="bar" width={width} height={height} /> |
| 96 | + </div> |
| 97 | + ); |
| 98 | +}); |
| 99 | + |
| 100 | +export default ChartBar; |
0 commit comments