当前位置:网站首页>关于chartjs 屏幕大小自适应
关于chartjs 屏幕大小自适应
2022-04-22 13:15:00 【shmilyhq】
html 代码
<div class="">
<div id="popChart" style="width: 100%;height:300px;"></div>
</div>
引用 echarts.js
<!--echarts-->
<script src="/js/chart/echarts.min.js" type="text/javascript"></script>
js代码
let system = "";
if ($('#source').val().length != 0){
system += '-'+ $('#source option:selected').text();
}
let text = '【'+$('#year').val()+system+'】数量柱状图';
let myChart = echarts.init(document.getElementById('popChart'));
myChart.clear();
$.ajax({
method: 'get',
url: "xxx/list",
data: date,
success: function (r) {
if (r.code == 0) {
let dataTrans = JSON.parse(r.msg);
let option = {
title:{
text: text, //标题
x: 'center', //水平居中
},
tooltip: {
trigger: 'item',
formatter: "{b} : {c}" //鼠标悬浮显示x/y轴的值
},
//x轴
xAxis: {
name: '月份',
type: 'category',
data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
},
//y轴
yAxis: {
name: '数量',
},
series: [{
data: [
dataTrans['januaryNum'],
dataTrans['februaryNum'],
dataTrans['marchNum'],
dataTrans['aprilNum'],
dataTrans['mayNum'],
dataTrans['juneNum'],
dataTrans['julyNum'],
dataTrans['augustNum'],
dataTrans['septemberNum'],
dataTrans['octoberNum'],
dataTrans['novemberNum'],
dataTrans['decemberNum']
],
type: 'bar', //图标类型 柱状图
itemStyle: {
background:'#3A7BD5', // 图形颜色
normal: {
color: '#3A7BD5', //字体颜色
label: {
show: true, //开启显示
position: 'top', //在上方显示
textStyle: {
//数值样式
color: '#3A7BD5', //数值颜色
fontSize: 12, //字体大小
},
},
},
},
}]
};
myChart.setOption(option, true); //加载数据
//屏幕自适应关键代码
window.addEventListener("resize", function () {
myChart.resize(); });
} else {
layer.msg(r.msg);
}
}
});
效果如下图所示:

版权声明
本文为[shmilyhq]所创,转载请带上原文链接,感谢
https://blog.csdn.net/shmilyhq/article/details/124317541
边栏推荐
- VMware虚拟机克隆后NAT模式下网络的配置
- SPI协议的通信原理
- Panel data of green total factor productivity of gtfp in all provinces (2004-2018)
- Advertising offensive and defensive war of Internet giants
- Oracle netsuite customers say | the "core secret script" for more detailed process control of China Film Barco
- When doing correlation analysis, how to exclude singular value outliers to increase the accuracy of correlation analysis
- C whether the administrator has the authority to run the software
- C custom button implementation source code
- The compatibility certification of ecological Wanli database and Yixin technology has been completed
- Wong Kwong Yu Kwai tiktok is unable to sleep soundly.
猜你喜欢

The data in MATLAB is forcibly converted from double type to uint8, which is rounded, and the basic data type of MATLAB is attached

Oplg: new generation cloud primary observable best practices

Example accumulation of two-dimensional line drawing function plot () in MATLAB

RedisConfig配置类

OPLG:新一代云原生可观测最佳实践

no main manifest attribute / .jar中没有主清单属性

互联网巨头的广告攻守战

Station B cuts to the live broadcast, sooner or later

From construction to governance, the industry's first white paper on microservice governance technology was officially released (including a free download link)

Rust实现斐波那契数
随机推荐
ROS2——什么是接口
How to batch delete worksheets in Excel
Type requirements for parameters pT1 and pT2 of OpenCV function line()
POJ 3259 最短路SPFA + 负环 (模板)
Oracle netsuite customers say | the "core secret script" for more detailed process control of China Film Barco
我们需要什么样的数据库产品
封装统一响应结果枚举类(工具模块)
Tobin Q data - Shanghai and Shenzhen A-share listed companies (including industry name, code and other indicators) 2003-2020
如何实现数组和 List 之间的转换?
BPMN - 如何绘制符合良构编排的基础BPMN?
mysql FUNCTION xxx.charindex does not exist
Oplg: new generation cloud primary observable best practices
浅学一下Shell脚本(5)--函数,随机数,正则表达式
如何使用Colormaps和自定义自己喜欢的colorbar?
ROS2——手把手教你编写一个话题
Fade in and fade out function of C form (project source code)
Xen热修复技术(基础了解)
ROS Robot Learning -- kinematics solution of mcnamu wheel
R language uses dhyper function to generate hypergeometric distribution density data and plot function to visualize hypergeometric distribution density data
The sales volume is cut by half, and there is no blueprint for lantu