Chart / olddataset /web /Vchart /pie /chart_0024_pie.html
Pekku's picture
Upload folder using huggingface_hub
79dc9c8 verified
<div id="chart" style="width:100%;height:520px;"></div>
<script src="https://cdn.jsdelivr.net/npm/@visactor/vchart/build/index.min.js"></script>
<script>
// 这里粘贴你的那段 JS 代码
const data = [
{ type: 'oxygen', value: '46.60', formula: 'O', texture: 'circle' },
{ type: 'silicon', value: '27.72', formula: 'Si', texture: 'horizontal-line' },
{ type: 'aluminum', value: '8.13', formula: 'Al', texture: 'vertical-line' },
{ type: 'iron', value: '5', formula: 'Fe', texture: 'rect' },
{ type: 'calcium', value: '3.63', formula: 'Ca', texture: 'grid' },
{ type: 'sodium', value: '2.83', formula: 'Na', texture: 'bias-rl' },
{ type: 'potassium', value: '2.59', formula: 'K', texture: 'diamond' },
{ type: 'others', value: '3.5', formula: 'Others', texture: 'bias-lr' }
];
const spec = {
type: 'pie',
data: [
{
id: 'id0',
values: data
}
],
outerRadius: 0.8,
innerRadius: 0.5,
padAngle: 0.6,
valueField: 'value',
categoryField: 'type',
pie: {
style: {
cornerRadius: 10,
texture: datum => datum['texture']
},
state: {
hover: {
outerRadius: 0.85,
stroke: '#000',
lineWidth: 1
},
selected: {
outerRadius: 0.85,
stroke: '#000',
lineWidth: 1
}
}
},
title: {
visible: true,
text: 'Statistics of Surface Element Content'
},
indicator: {
visible: true,
trigger: 'hover',
limitRatio: 0.4,
title: {
visible: true,
autoFit: true,
style: {
fontWeight: 'bolder',
fontFamily: 'Times New Roman',
fill: '#888',
text: datum => {
const d = datum ?? data[0];
return d['formula'];
}
}
},
content: [
{
visible: true,
style: {
fontSize: 20,
fill: 'orange',
fontWeight: 'bolder',
fontFamily: 'Times New Roman',
text: datum => {
const d = datum ?? data[0];
return d['type'];
}
}
},
{
visible: true,
style: {
fontSize: 18,
fill: 'orange',
fontFamily: 'Times New Roman',
text: datum => {
const d = datum ?? data[0];
return d['value'] + '%';
}
}
}
]
},
legends: {
visible: true,
orient: 'left',
item: {
shape: {
style: {
symbolType: 'circle',
texture: datum => datum['texture']
}
}
}
},
tooltip: {
mark: {
content: [
{
key: datum => datum['type'],
value: datum => datum['value'] + '%'
}
]
}
}
};
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>