zhenxun_bot/resources/template/bar_chart/main.html

59 lines
1.7 KiB
HTML
Raw Normal View History

2024-08-25 00:02:35 +08:00
<!DOCTYPE html>
<html>
2024-09-29 17:00:31 +08:00
2024-08-25 00:02:35 +08:00
<head>
<meta charset="utf-8">
<title>ECharts Example</title>
<!-- 引入ECharts -->
<script src="https://cdn.bootcss.com/echarts/4.2.1/echarts.min.js"></script>
<link rel="stylesheet" href="main.css">
</head>
2024-09-29 17:00:31 +08:00
2024-08-25 00:02:35 +08:00
<body>
<!-- 图表容器 -->
<div id="main" style="width: 1000px;height:500px;"></div>
2024-09-29 17:00:31 +08:00
2024-08-25 00:02:35 +08:00
<script type="text/javascript">
// 基于准备好的dom初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
2024-09-29 17:00:31 +08:00
2024-08-25 00:02:35 +08:00
// 指定图表的配置项和数据
var option = {
xAxis: {
type: 'value',
boundaryGap: [0, 0.01]
},
yAxis: {
type: 'category',
2024-09-29 17:00:31 +08:00
data: {
{
data.category_data | tojson
}
}
2024-08-25 00:02:35 +08:00
},
2024-09-29 17:00:31 +08:00
series: [{
data: {
{
data.data | tojson
}
},
type: 'bar',
itemStyle: {
// 为每个柱子设置随机颜色
color: function () {
// 生成一个随机颜色
return 'rgb(' +
Math.round(Math.random() * 255) + ',' +
Math.round(Math.random() * 255) + ',' +
Math.round(Math.random() * 255) + ')';
}
2024-08-25 00:02:35 +08:00
}
2024-09-29 17:00:31 +08:00
}]
};
2024-08-25 00:02:35 +08:00
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
</script>
</body>
2024-09-29 17:00:31 +08:00
2024-08-25 00:02:35 +08:00
</html>