1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
| <!DOCTYPE html> <html lang="en">
<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <meta name="chart-name" content="雷达面积图"> <title>F2 图表组件库 - AntV</title> <link rel="stylesheet" href="https://gw.alipayobjects.com/os/rmsportal/YmDAMEQVbLJpVbKiRQVX.css" /> <style> .mountNode { width: 400px; height: 300px; }
.aws-tooltip { position: absolute; background: #ccc; font-size: 28px; width: 50px; height: 50px; line-height: 50px; text-align: center; border-radius: 50%; }
.aws-tooltip::after { content: ''; position: absolute; left: 0; top: 0; width: 20px; height: 20px; background: #000; } </style> <script>/*Fixing iframe window.innerHeight 0 issue in Safari*/document.body.clientHeight;</script>
<script src="https://gw.alipayobjects.com/os/antv/assets/f2/3.3.0/f2.min.js"></script> <script src="https://gw.alipayobjects.com/os/antv/assets/lib/lodash-4.17.4.min.js"></script> <script src="https://gw.alipayobjects.com/os/antv/assets/lib/jquery-3.2.1.min.js"></script> <!-- 在 PC 上模拟 touch 事件 --> <script src="https://gw.alipayobjects.com/os/rmsportal/NjNldKHIVQRozfbAOJUW.js"></script> </head>
<body>
<div class="content"> <canvas id="mountNode" class="mountNode"></canvas> <div class="aws-tooltip"> <span></span> </div> </div> <script> var canvasOffsetTop = $('#mountNode').position().top; var canvasOffsetLeft = $('#mountNode').position().left; console.log(canvasOffsetTop, canvasOffsetLeft); const _this = this; let list = [{ text: '拔尖', num: 0, }, { text: '优秀', num: 22, }, { text: '高潜力', num: 16, }, { text: '中等', num: 26, }, { text: '不足', num: 12, }, { text: '待提高', num: 26, }] var chart = new F2.Chart({ id: 'mountNode', pixelRatio: window.devicePixelRatio, }); chart.source(list, { // 数据传出入 num: { // ticks: [], tickCount: 5, min: 0, }, text: { tickCount: 7, range: [0, 1], },
});
chart.axis('text', { // 底部样式 line: // null, { strokeStyle: { color: '#000' }, lineWidth: '3', strokeOpacity: '0.8', shadowColor: '#04ca73', shadowBlur: '3', }, tickLine: { lineWidth: 1, stroke: '#ccc', length: 5, // 刻度线长度 }, label: function label(text, index, total) { var cfg = { textAlign: 'center', fill: '#04ca73', fontSize: 12, fontWeight: 700, }; return cfg; }, });
chart.axis('num', { label: { fill: '#000', }, line: { stroke: '#9ec3b8', }, // grid: { // lineDash: null, // stroke: '#54b858', // }, }); chart.tooltip({ // 提示消息 showCrosshairs: false, custom: true, // 是否自定义 tooltip 提示框 showTooltipMarker: true, // 是否显示 tooltipMarker tooltipMarkerStyle: { // 点的样式 fill: { color: '#000' }, // 设置 tooltipMarker 的样式 stroke: '#1890ff', fillOpacity: 0.8, lineWidth: '3', shadowColor: '#04ca73', shadowBlur: '10', }, onHide(obj) { // tooltip 隐藏时的回调函数 // console.log('onHide', obj); // obj: { x, y, title, items } }, onChange(obj) { // tooltip 内容发生改变时的回调函数 // console.log('onChange', obj); // obj: { x, y, title, items } const tooltipEl = $('.aws-tooltip'); const currentData = obj.items[0]; const text = currentData.value; // console.log('onChange', currentData, text); tooltipEl.html([`<span>${text}</span>`].join('')); tooltipEl.css({ opacity: 1, left: `${canvasOffsetLeft + currentData.x - parseInt(tooltipEl.css('width').replace('px', ''), 0) / 2.0}px`, top: `${canvasOffsetTop + currentData.y - tooltipEl.height() - 15}px`, }); }, });
// 线条的样式 chart.line().position('text*num').color('l(0) 0:#1890FF 1:#f7f7f7').shape('smooth') .size(5) .style({ shadowColor: '#04ca73', shadowBlur: '100', }); // 下方渐变的样式 chart.area().position('text*num').color('l(90) 0:#000 1:#f7f7f7').shape('smooth'); // 点的样式 // chart.point().position('text*num').color('#EED5FF').size(5); chart.render(); </script>
</body>
</html>
|