以时间(从后台读取,设置刷新的时间间隔)为横坐标的折线图,附带饼图的实现

本文主要是介绍以时间(从后台读取,设置刷新的时间间隔)为横坐标的折线图,附带饼图的实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 

1. 使用插件 Chart.js 下载地址:https://github.com/chartjs/Chart.js/blob/master/LICENSE.md

2. JS实现(需要根据后台数据进行解析)

$.ajax({type: "POST",cache: false,dataType: "json",url: g_pageName,data: {"code": "OPHS_24h_Bl_stat"},success: function (data) {var json = eval(data); //数组// 生成表格数据function randomBar(date, y1) {return {t: date.valueOf(),y: y1};}var dateFormat = 'YYYY-MM-DD HH:mm:ss';var date = moment(json[0][0], dateFormat);var likesd = [randomBar(date, json[1][0])];var likesf = [randomBar(date, json[2][0])];var likesr = [randomBar(date, json[3][0])];var likess = [randomBar(date, json[4][0])];var likesp = [randomBar(date, json[5][0])];var likesy = [randomBar(date, json[6][0])];var labels = [date];for(var j=1; j<json[0].length-1; j++) {date = date.clone().add(1, 'hour');likesd.push(randomBar(date, json[1][j]));likesf.push(randomBar(date, json[2][j]));likesr.push(randomBar(date, json[3][j]));likess.push(randomBar(date, json[4][j]));likesp.push(randomBar(date, json[5][j]));likesy.push(randomBar(date, json[6][j]));labels.push(date);}var cfg = {labels: labels,type: 'line',datasets: [{label: '目录告警',data: likesd,type: 'line',borderColor: window.chartColors.yellow,backgroundColor: window.chartColors.yellow,pointRadius: 1,fill: false,lineTension: 0.5,borderWidth: 1}, {label: '文件告警',data: likesf,type: 'line',borderColor: window.chartColors.blue,backgroundColor: window.chartColors.blue,pointRadius: 1,fill: false,lineTension: 0.5,borderWidth: 1}, {label: '注册表告警',data: likesr,type: 'line',borderColor: window.chartColors.green,backgroundColor: window.chartColors.green,pointRadius: 1,fill: false,lineTension: 0.5,borderWidth: 1}, {label: '服务告警',data: likess,type: 'line',borderColor: '#669999',backgroundColor: '#669999',pointRadius: 1,fill: false,lineTension: 0.5,borderWidth: 1}, {label: '进程告警',data: likesp,type: 'line',borderColor: '#99cccc',backgroundColor: '#99cccc',pointRadius: 1,fill: false,lineTension: 0.5,borderWidth: 1}, {label: '系统防篡改告警',data: likesy,type: 'line',borderColor: '#4A708B',backgroundColor: '#4A708B',pointRadius: 1,fill: false,lineTension: 0.5,borderWidth: 1}]};// var chart = new Chart(ctx, cfg);var ctx = document.getElementById('doChart1').getContext('2d');ctx.canvas.width = 1000;ctx.canvas.height = 350;window.myLine = Chart.Line(ctx, {data: cfg,options: {animation: false,responsive: true,hoverMode: 'index',stacked: false,legend: {display: true,position: 'right',labels: {boxWidth: 13,}},/*title: {display: true,text: '过去24小时告警'},*/scales: {xAxes: [{scaleLabel: {display: true,labelString: '时间'},type: 'time',time: {displayFormats: {minute: 'DD'+'日'+'HH'+'点',},tooltipFormat: 'YYYY'+'年'+'MM'+'月'+'DD'+'日'+'HH'+'点',},distribution: 'series',ticks: {source: 'labels'}}],yAxes: [{scaleLabel: {display: true,labelString: '告警次数'},type: 'linear', //only linear but allow scale type registration. This allows extensions to exist solely for log scale for instancedisplay: true,gridLines: {opacity: 0.5,lineWidth: 0.5},}],}}});},error: function(xhr, errmsg, err) {console.log(xhr.status + ": " + xhr.responseText);}});

 

 

这篇关于以时间(从后台读取,设置刷新的时间间隔)为横坐标的折线图,附带饼图的实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/729138

相关文章

Flutter实现文字镂空效果的详细步骤

《Flutter实现文字镂空效果的详细步骤》:本文主要介绍如何使用Flutter实现文字镂空效果,包括创建基础应用结构、实现自定义绘制器、构建UI界面以及实现颜色选择按钮等步骤,并详细解析了混合模... 目录引言实现原理开始实现步骤1:创建基础应用结构步骤2:创建主屏幕步骤3:实现自定义绘制器步骤4:构建U

SpringBoot中四种AOP实战应用场景及代码实现

《SpringBoot中四种AOP实战应用场景及代码实现》面向切面编程(AOP)是Spring框架的核心功能之一,它通过预编译和运行期动态代理实现程序功能的统一维护,在SpringBoot应用中,AO... 目录引言场景一:日志记录与性能监控业务需求实现方案使用示例扩展:MDC实现请求跟踪场景二:权限控制与

Android实现定时任务的几种方式汇总(附源码)

《Android实现定时任务的几种方式汇总(附源码)》在Android应用中,定时任务(ScheduledTask)的需求几乎无处不在:从定时刷新数据、定时备份、定时推送通知,到夜间静默下载、循环执行... 目录一、项目介绍1. 背景与意义二、相关基础知识与系统约束三、方案一:Handler.postDel

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设

使用Python实现IP地址和端口状态检测与监控

《使用Python实现IP地址和端口状态检测与监控》在网络运维和服务器管理中,IP地址和端口的可用性监控是保障业务连续性的基础需求,本文将带你用Python从零打造一个高可用IP监控系统,感兴趣的小伙... 目录概述:为什么需要IP监控系统使用步骤说明1. 环境准备2. 系统部署3. 核心功能配置系统效果展

Java controller接口出入参时间序列化转换操作方法(两种)

《Javacontroller接口出入参时间序列化转换操作方法(两种)》:本文主要介绍Javacontroller接口出入参时间序列化转换操作方法,本文给大家列举两种简单方法,感兴趣的朋友一起看... 目录方式一、使用注解方式二、统一配置场景:在controller编写的接口,在前后端交互过程中一般都会涉及

Python实现微信自动锁定工具

《Python实现微信自动锁定工具》在数字化办公时代,微信已成为职场沟通的重要工具,但临时离开时忘记锁屏可能导致敏感信息泄露,下面我们就来看看如何使用Python打造一个微信自动锁定工具吧... 目录引言:当微信隐私遇到自动化守护效果展示核心功能全景图技术亮点深度解析1. 无操作检测引擎2. 微信路径智能获

Python中pywin32 常用窗口操作的实现

《Python中pywin32常用窗口操作的实现》本文主要介绍了Python中pywin32常用窗口操作的实现,pywin32主要的作用是供Python开发者快速调用WindowsAPI的一个... 目录获取窗口句柄获取最前端窗口句柄获取指定坐标处的窗口根据窗口的完整标题匹配获取句柄根据窗口的类别匹配获取句

在 Spring Boot 中实现异常处理最佳实践

《在SpringBoot中实现异常处理最佳实践》本文介绍如何在SpringBoot中实现异常处理,涵盖核心概念、实现方法、与先前查询的集成、性能分析、常见问题和最佳实践,感兴趣的朋友一起看看吧... 目录一、Spring Boot 异常处理的背景与核心概念1.1 为什么需要异常处理?1.2 Spring B

python处理带有时区的日期和时间数据

《python处理带有时区的日期和时间数据》这篇文章主要为大家详细介绍了如何在Python中使用pytz库处理时区信息,包括获取当前UTC时间,转换为特定时区等,有需要的小伙伴可以参考一下... 目录时区基本信息python datetime使用timezonepandas处理时区数据知识延展时区基本信息