File size: 3,994 Bytes
7b52e07 | 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 | <!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>VChart Area Demo</title>
<!-- 1) 引入 VChart(CDN) -->
<!-- 如果这个不通,再把它换成:https://unpkg.com/@visactor/vchart/build/index.min.js -->
<script src="_deps/cdn.jsdelivr.net/npm/@visactor/vchart/build/index.min.js"></script>
<style>
/* 2) 给容器一个高度,不然你可能看不到图 */
#chart {
width: 100%;
height: 520px;
}
</style>
</head>
<body>
<!-- 3) 图表容器:id 要和下面 JS 里的 dom 对上 -->
<div id="chart"></div>
<script>
const data = [
{
name: 'boxPlot',
values: [
{
x: 'Sub-Saharan Africa',
y1: 9.16270124,
y2: 10.07530816,
y3: 10.09027907,
y4: 10.27579542,
y5: 11.62222959,
group: 'High income'
},
{
x: 'Sub-Saharan Africa',
y1: 8.721525214,
y2: 9.641352839,
y3: 10.1736233,
y4: 10.57169914,
y5: 11.64427467,
group: 'Low income'
},
{
x: 'South Asia',
y1: 9.404757278,
y2: 10.36482449,
y3: 10.94903493,
y4: 11.5806383,
y5: 12.50192084,
group: 'Low income'
},
{
x: 'South Asia',
y1: 9.732841997,
y2: 9.732841997,
y3: 9.732841997,
y4: 9.732841997,
y5: 9.732841997,
group: 'High income'
},
{
x: 'Middle East & North Africa',
y1: 9.541951901,
y2: 10.33719892,
y3: 10.91206173,
y4: 11.29821858,
y5: 11.60653481,
group: 'Low income'
},
{
x: 'Middle East & North Africa',
y1: 10.2396509,
y2: 10.63879995,
y3: 11.09996104,
y4: 11.54301107,
y5: 11.92092709,
group: 'High income'
},
{
x: 'Latin America & Caribbean',
y1: 10.14653181,
y2: 10.32106777,
y3: 10.45467215,
y4: 10.45844052,
y5: 10.6064696,
group: 'Low income'
},
{
x: 'Latin America & Caribbean',
y1: 8.743652009,
y2: 9.413881158,
y3: 10.16606248,
y4: 11.00011805,
y5: 12.20655104,
group: 'High income'
},
{
x: 'East Asia & Pacific',
y1: 7.800035977,
y2: 8.850646235,
y3: 10.14633178,
y4: 11.59877618,
y5: 13.24880824,
group: 'High income'
},
{
x: 'East Asia & Pacific',
y1: 8.316035904,
y2: 9.038602613,
y3: 10.22954548,
y4: 10.71782871,
y5: 12.07411874,
group: 'Low income'
},
{
x: 'Europe & Central Asia',
y1: 9.831631935,
y2: 9.939275167,
y3: 10.39108655,
y4: 10.95556656,
y5: 11.3012157,
group: 'Low income'
},
{
x: 'Europe & Central Asia',
y1: 9.522480948,
y2: 10.43085982,
y3: 11.06642694,
y4: 11.73822523,
y5: 12.62940296,
group: 'High income'
}
]
}
];
const spec = {
type: 'boxPlot',
data: data,
xField: ['x', 'group'],
minField: 'y1',
q1Field: 'y2',
medianField: 'y3',
q3Field: 'y4',
maxField: 'y5',
seriesField: 'group',
direction: 'vertical',
color: ['#BBD6B8', '#EA5455'],
legends: [{ visible: true }],
title: {
visible: true,
text: 'Global GDP 2021'
},
boxPlot: {
style: {
boxWidth: 50,
shaftWidth: 30,
shaftShape: 'bar',
lineWidth: 2,
shaftOpacity: 0.3
}
}
};
const vchart = new VChart.default(spec, { dom: "chart" });
vchart.renderSync();
// Just for the convenience of console debugging, DO NOT COPY!
window['vchart'] = vchart;
// 只要记得:dom 要写成 "chart"
</script>
</body>
</html>
|