echart图表之highcharts

news/2024/7/11 2:00:44 标签: javascript, 前端, jquery

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 前言
  • 一、HighCharts是什么?
  • 二、使用步骤
    • 1.引入库
    • 2.前端代码
    • 3.展现结果
    • 4.后台自动截图
  • 总结


前言

提示:这里可以添加本文要记录的大概内容:

前段时间公司要统计各个站的OEE机台的使用率,在网页上前端上展现OEE图表,难点在与如何将这些数据转成合理的数据展现出来


提示:以下是本篇文章正文内容,下面案例可供参考

一、HighCharts是什么?

1、HighCharts是网页报表工具,开发语言是Javascript
2、HighCharts是一个简单易用、美观、跨平台、跨浏览器的,兼容 IE6+、完美支持移动端、图表类型丰富、方便快捷的 HTML5 交互性图表库
3、HighCharts支持图表的类型有:曲线图、柱状图、饼状图、区域图、散点图、综合图的各种图表需求。

二、使用步骤

1.引入库

代码如下(示例):

1、引入Jquery(HighCharts是基于Jquery框架开发的)
2、引入HighCharts.js
3、引入exporting.js(导出功能)

2.前端代码

代码如下(示例):

    <script type="text/javascript">
        var operData = [];
        $(document).ready(function () {

            var options = {
                chart: {
                    type: 'column',
                    events: {
                        drilldown: function (e) {
                            //alert("dddd");
                        }
                    }
                },
                colors: ['#00FFFF', '#0066FF', '#FF0000', '#990033', '#FFC000', '#FF0000', '#8d4653', '#8085e9', '#f15c80', '#e4d354', '#8085e8'],
                title: {
                    text: '各工序的OEE'
                   
                },
                subtitle: {
                    text: '点击可查看具体的版本数据,数据来源: <a href="#"></a>.'
                   
                },
                xAxis: {
                    type: 'category'
                },
                yAxis: {
                    title: {
                        text: 'OEE'
                    },
                    tickPositions: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
                },
                legend: {
                    enabled: true
                },
                plotOptions: {
                    series: {
                        borderWidth: 1,
                        borderColor: "#FFFFFF",
                        borderRadius: 2,
                        dataLabels: {
                            enabled: true,
                            format: '{point.y:.1f}%'
                        }
                    },
                    column: {
                        stacking: 'normal',
                        cursor: 'pointer',
                        point: {
                            events: {
                                click: function (e) {
                                    if (e.point.name != null) {
                                        //alert(e.point.name);
                                        var type = $("#<%=ddlType.ClientID %>").val();
                                        var year = $("#<%=ddlYear.ClientID %>").val();
                                        var monthWeekly = $("#<%=ddlMonthWeekly.ClientID %>").val();
                                        var day = $("#<%=ddlDay.ClientID %>").val();
                                        var depart = $("#<%=ddlOcapDepart.ClientID %>").val();

                                        var ndate = "";
                                        if (type == "Daily") {
                                            ndate = year + monthWeekly + day;
                                        } else if (type == "Weekly") {
                                            ndate = year + monthWeekly
                                        } else if (type == "Monthly") {
                                            ndate = year + monthWeekly
                                        }
                                        var title = type + "_" + ndate + "_" + depart + "_EquipList";

                                        $("#<%=HiddenField1.ClientID %>").val(e.point.name);
                                        $("#equipid").val("");
                                        $("#searchInfo").show();
                                        InitGird(title, type, ndate, depart, e.point.name);
                                    }
                                }
                            }
                        }
                    }
                },
                tooltip: {
                    useHTML: true,
                    style: {
                        padding: 0,
                        pointerEvents: 'auto'
                    },
                    shared: false,
                    formatter: function () {
                        var type = $("#<%=ddlType.ClientID %>").val();
                        var year = $("#<%=ddlYear.ClientID %>").val();
                        var monthWeekly = $("#<%=ddlMonthWeekly.ClientID %>").val();
                        var day = $("#<%=ddlDay.ClientID %>").val();
                        var depart = $("#<%=ddlOcapDepart.ClientID %>").val();
                        if (type == "Daily") {
                            ndate = year + monthWeekly + day;
                        } else if (type == "Weekly") {
                            ndate = year + monthWeekly
                        } else if (type == "Monthly") {
                            ndate = year + monthWeekly
                        }
                        if (type == "Daily") {
                            return this.series.name + "<br/>" + this.point.name + ': ' + this.point.y.toFixed(1) + '%';
                        } else {
                            return this.series.name + "<br/>" + '<a href="http://localhost:48057/Summary_OEE_Report_Oper_Detail.aspx?type=' + type + '&oper=' + this.point.name + '&ndate=' + ndate + '&depart=' + depart + '" target="_blank">' + this.point.name + ': ' + this.point.y.toFixed(1) + '%' + '</a>'
                        }
                    }
                },
                series: [],
                drilldown: {
                    series: []
                }
            };

3.展现结果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

4.后台自动截图

1、在服务器上部署自动截图的API
http://*********:11942/
2、创建模板

{
	"chart": {
		"width": 900,
		"type": "column"
	},
	"credits":false,
	"colors": [
		"#00FFFF",
		"#0066FF",
		"#FF0000",
		"#990033",
		"#FFC000",
		"#FF0000",
		"#8d4653",
		"#8085e9",
		"#f15c80",
		"#e4d354",
		"#8085e8"
	],
	"title": {
		"text": "$title"
	},
	"subtitle": {
		"text": ""
	},
	"xAxis": {
	    "type": "category",
		"labels": {
                "style": {
                    "fontWeight": "bold"
                }
            }
    },
	"yAxis": {
		"title": {
			"text": "OEE(%)"
		},
		
		"tickPositions": [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
	},
	"legend": {
		"enabled": true
	},
	"plotOptions": {
		"series": {
			"borderWidth":1,
			"borderColor": "white",
			"borderRadius":2,
			"dataLabels": {
				"enabled": true,
				"format":"{point.y:.1f}%"
			}
		},
		"column": {
	        "stacking": "normal",
	        "cursor": "pointer",
	        "dataLabels": {
		        "enabled": true,
		        "color": "white",
		        "style": {
			        "textShadow": "0 0 3px black",
					"fontWeight": "bold"
		        }
	        }
        }
	},
	"tooltip": {
        "useHTML": true,
        "style": {
            "padding": 0,
            "pointerEvents": "auto"
        },
	    "shared": false
	 },
	"series": [$series],
    "drilldown": {
	    "series": [$drilldown]
    }
}

3、调用API接口生成图片

  string chartJsonPath = Environment.CurrentDirectory + "//Json//chart.json";
            StreamReader sr = new StreamReader(chartJsonPath, Encoding.Default);
            string line;
            string jsonobj = "";
            while ((line = sr.ReadLine()) != null)
            {
                jsonobj = jsonobj + line.ToString();
            }

            string url = System.Configuration.ConfigurationSettings.AppSettings["PhantomjsUrl"].ToString();
            string param = jsonobj.Replace("$series", sbSerie.ToString()).Replace("$drilldown", sbDrilldownSerie.ToString()).Replace("$title", type + "_" + ndate + "_" + depart + "_OEE");

            KTD.Utilities.BaseUtils.FileUtils.CreateFile(Encoding.UTF8.GetBytes(param), Environment.CurrentDirectory + "//Json//" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".json");
            byte[] bytes;
            var client = new HttpClient();
            HttpContent content = HttpContent.Create(Encoding.UTF8.GetBytes(param), "application/json");
            using (HttpResponseMessage responseMessage = client.Post(url, content))
            {
                responseMessage.EnsureStatusIsSuccessful();
                bytes = responseMessage.Content.ReadAsByteArray();
            }

            MemoryStream stream = new MemoryStream(bytes);
            Bitmap bmp = new Bitmap(stream);
            string randomName = ndate +"_"+ depart+".png";
            string saveUrl = System.Configuration.ConfigurationSettings.AppSettings["SaveUrl"].ToString() + "//" + randomName;
            bmp.Save(saveUrl, ImageFormat.Png);
            stream.Dispose();
            stream.Close();
            bmp.Dispose();

3、截图效果如下
在这里插入图片描述


总结

发现截来的图片和系统执行出来的图样式不能完全一模一样,估计是使用脚本的版本不一样导致。


http://www.niftyadmin.cn/n/152968.html

相关文章

p81 红蓝对抗-AWD 监控不死马垃圾包资源库

数据来源 注意&#xff1a;一下写的东西是在p80 红蓝对抗-AWD 模式&准备&攻防&监控&批量这篇文章的基础上进行的 演示案例&#xff1a; 防守-流量监控-实时获取访问数据包流量 攻击-权限维持-不死脚本后门生成及查杀 其他-恶意操作-搅屎棍发包回首掏共权限…

Java的SPI

Java SPI&#xff08;Service Provider Interface&#xff09;是一种在 Java 平台上用于服务发现的机制&#xff0c;允许应用程序在运行时动态加载实现某一接口的类&#xff0c;并通过接口进行交互。 在 Java SPI 中&#xff0c;有三个角色&#xff1a;服务提供者、服务请求者、…

Understanding topics:理解话题(Topic)

文章目录背景1. 准备工作2. rqt_graph3. ros2 topic list 命令4. ros2 topic echo 命令5. ros2 topic info 命令6. ros2 interface show 命令7. ros2 topic pub 命令8. ros2 topic hz 命令9. 清理参考官方文档&#xff1a;Understanding topics 背景 ROS 2将复杂的系统分解成…

Arduino 驱动DS1307时钟模块使用介绍

Arduino 驱动DS1307时钟模块使用介绍 🔖DS1307时钟模块 📍DS1307时钟模块资料 https://pan.baidu.com/s/1mtXruLAktZj7UDhFD54BNw 提取码:d9xh 📋模块简介:DS1307 I2C实时时钟芯片(RTC) 24C32 32K I2C EEPROM存储器 解决DS1307带备用电池不能读写的问题。 充满电后,…

企业搭建FAQ的详细步骤及工具推荐!

FAQ是“常见问题解答”&#xff08;Frequently Asked Questions&#xff09;的缩写&#xff0c;是一种经典的帮助中心内容类型。FAQ通常包含用户经常提出的问题和对应的解答&#xff0c;旨在为用户提供快速和准确的帮助。以下是FAQ的特点和编写方法&#xff1a;特点&#xff1a…

工具、学习网站

目录 图片处理工具1.BgRemover-在线图片去底工具2.Convertio-文件转换器3.视频转音频4.视频转 Gif5.传图识色6.本地图片在线存储引用 - Image Upload7.RGB CMYK 转换工具各大工具网站入口极简壁纸图片视频素材网壁纸网站 一天一个不重样查询自己博客的内容摸鱼&#xff1a;学习…

Spring Boot 3.0系列【18】核心特性篇之单元测试和热部署

有道无术,术尚可求,有术无道,止于术。 本系列Spring Boot版本3.0.3 源码地址:https://gitee.com/pearl-organization/study-spring-boot3 文章目录 单元测试Junit 5 简介入门案例常用注解@SpringBootTest@Test@DisplayName@BeforeEach、@AfterEach@BeforeAll、@AfterAll其…

【华为机试真题详解 Python实现】最差产品奖【2023 Q1 | 100分】

文章目录 前言题目描述输入描述输出描述示例 1题目解析参考代码前言 《华为机试真题详解》专栏含牛客网华为专栏、华为面经试题、华为OD机试真题。 如果您在准备华为的面试,期间有想了解的可以私信我,我会尽可能帮您解答,也可以给您一些建议! 本文解法非最优解(即非性能…