|
| 1 | +import { Column } from '@ant-design/plots'; |
| 2 | +import React from 'react'; |
| 3 | +import ReactDOM from 'react-dom'; |
| 4 | + |
| 5 | +const DemoAnnotationShape = () => { |
| 6 | + const data = [ |
| 7 | + { month: 'Jan.', profit: 387264, start: 0, end: 387264 }, |
| 8 | + { month: 'Feb.', profit: 772096, start: 387264, end: 1159360 }, |
| 9 | + { month: 'Mar.', profit: 638075, start: 1159360, end: 1797435 }, |
| 10 | + { month: 'Apr.', profit: -211386, start: 1797435, end: 1586049 }, |
| 11 | + { month: 'May', profit: -138135, start: 1586049, end: 1447914 }, |
| 12 | + { month: 'Jun', profit: -267238, start: 1447914, end: 1180676 }, |
| 13 | + { month: 'Jul.', profit: 431406, start: 1180676, end: 1612082 }, |
| 14 | + { month: 'Aug.', profit: 363018, start: 1612082, end: 1975100 }, |
| 15 | + { month: 'Sep.', profit: -224638, start: 1975100, end: 1750462 }, |
| 16 | + { month: 'Oct.', profit: -299867, start: 1750462, end: 1450595 }, |
| 17 | + { month: 'Nov.', profit: 607365, start: 1450595, end: 2057960 }, |
| 18 | + { month: 'Dec.', profit: 1106986, start: 2057960, end: 3164946 }, |
| 19 | + { month: 'Total', start: 0, end: 3164946 }, |
| 20 | + ]; |
| 21 | + |
| 22 | + const config = { |
| 23 | + data, |
| 24 | + xField: 'month', |
| 25 | + yField: ['end', 'start'], |
| 26 | + colorField: (d) => (d.month === 'Total' ? 'Total' : d.profit > 0 ? 'Increase' : 'Decrease'), |
| 27 | + axis: { y: { labelFormatter: '~s' } }, |
| 28 | + tooltip: { |
| 29 | + items: [ |
| 30 | + { channel: 'y', valueFormatter: '~s' }, |
| 31 | + { channel: 'y1', valueFormatter: '~s' }, |
| 32 | + ], |
| 33 | + }, |
| 34 | + annotations: [ |
| 35 | + { |
| 36 | + type: 'shape', |
| 37 | + style: { |
| 38 | + x: '80%', |
| 39 | + y: '70%', |
| 40 | + render: ({ x, y }, context, d) => { |
| 41 | + const { document } = context; |
| 42 | + const g = document.createElement('g', {}); |
| 43 | + const c1 = document.createElement('circle', { |
| 44 | + style: { |
| 45 | + cx: x, |
| 46 | + cy: y, |
| 47 | + lineWidth: 4, |
| 48 | + r: 65, |
| 49 | + stroke: 'red', |
| 50 | + opacity: 0.3, |
| 51 | + }, |
| 52 | + }); |
| 53 | + const c2 = document.createElement('circle', { |
| 54 | + style: { |
| 55 | + cx: x, |
| 56 | + cy: y, |
| 57 | + lineWidth: 2, |
| 58 | + r: 50, |
| 59 | + stroke: 'red', |
| 60 | + opacity: 0.3, |
| 61 | + }, |
| 62 | + }); |
| 63 | + const text = document.createElement('text', { |
| 64 | + style: { |
| 65 | + x, |
| 66 | + y, |
| 67 | + text: '数据保密', |
| 68 | + transform: 'rotate(30)', |
| 69 | + fontSize: 20, |
| 70 | + fill: 'red', |
| 71 | + textAlign: 'center', |
| 72 | + textBaseline: 'middle', |
| 73 | + fillOpacity: 0.3, |
| 74 | + }, |
| 75 | + }); |
| 76 | + g.appendChild(c1); |
| 77 | + g.appendChild(c2); |
| 78 | + g.appendChild(text); |
| 79 | + return g; |
| 80 | + }, |
| 81 | + }, |
| 82 | + }, |
| 83 | + ], |
| 84 | + }; |
| 85 | + return <Column {...config} />; |
| 86 | +}; |
| 87 | + |
| 88 | +ReactDOM.render(<DemoAnnotationShape />, document.getElementById('container')); |
0 commit comments