背景:java开发的过程中,需要对数据进行可视化,这样方便客户理解此时的数据状态

语言:java,js,window7,echarts包文件

sample的例子下面的参照

https://www.echartsjs.com/examples/en/editor.html?c=line-sections

html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta name="viewport" charset="UTF-8"
content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
<title></title>
<meta name="viewport"
content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" />
<script th:src="@{jquery/js/jquery-3.2.0.min.js}" type="text/javascript"></script>
<script th:src="@{echarts/js/echarts.js}" type="text/javascript"></script>
<script th:src="@{js/testCharts.js}" type="text/javascript"></script> </head>
<body>
<div id="conditions"> <table>
<tr>
<td><label>検索条件:</label></td>
<td><input type="radio" name="month" id="month"
onclick="choseMonthOrDay(this)" /><label>月</label>
</td>
<td><input type="radio" name="month" id="month"
onclick="choseMonthOrDay(this)" /><label>年</label>
</td>
<td><input type="button" onclick="beforRet()"
style="background-color: #3987e4; width: 83px; height: 44px; border: 0;"
value="戻る"></input></td>
</tr>
</table>
</div> <div id="chart"></div>
<!-- <div id="chart"></div> -->
</body>
</html>

  

js

$(document).ready(function() {

//	$("#conditions").css("height", $(window).height()*0.1);
// $("#conditions").css("background-color", "#000000");
// alert($(window).width())
$("#chart").css("height", $(window).height()*0.8);
window.onresize = function() {
// $("#chart").css("height", $(window).height()*0.1);
$("#conditions").css("height", $(window).height()*0.8);
} var dataList
$.ajax({
url : "/testCharts/selectData",
type : 'post',
data : {
"habitSeq" : "2",
"value" : "01"
},
cache : false,
async : true,
success : function(data) {
dataList = JSON.parse(data);
chartsDisplay(dataList)
}
});
}) function chartsDisplay(dataList) { if (dataList.length != 0) {
var xAxisList = new Array();
var yAxisList = new Array();
for (var i = 0; i < dataList.length; i++) {
xAxisList[i] = (dataList[i]["maxInsDateTime"]);
yAxisList[i] = (dataList[i]["totalPrice"]);
}
var echart = echarts.init(document.getElementById('chart'));
var option = {
baseOption : {
title : {
text : '店舗売上状況',
subtext : '売上分析'
},
legend : {
data : [ '当月売上', '金額' ]
},
xAxis : {
data : xAxisList
// [ '周一', '周二', '周三', '周四', '周五', '周六', '周日' ]
},
yAxis : { },
tooltip : {
show : true,
formatter : '売上:{a}<br />日付:{b}<br />値:{c}'
},
series : [ {
name : '当月売上',
type : 'bar',
data : yAxisList ,// [ 200, 312, 431, 241, 175, 275,
// 369
// ],
markPoint : {
data : [ {
type : 'max',
name : '最大値'
}, {
type : 'min',
name : '最小値'
} ]
},
markLine : {
data : [ {
type : 'average',
name : '平均値',
itemStyle : {
normal : {
color : 'green'
}
}
} ]
}
}, {
name : '金額',
type : 'line',
data : yAxisList , // [ 321, 432, 543, 376, 286, 298,
// 400
// ],
markPoint : {
data : [ {
type : 'max',
name : '最大値'
}, {
type : 'min',
name : '最小値'
} ]
},
markLine : {
data : [ {
type : 'average',
name : '平均値',
itemStyle : {
normal : {
color : 'blue'
}
}
} ]
}
} ]
},
media : [ {
// 小与1000像素时候响应
query : {
maxWidth : 1000
},
option : {
title : {
show : true,
text : '测试一下'
}
}
} ]
};
// 每次窗口大小改变的时候都会触发onresize事件,这个时候我们将echarts对象的尺寸赋值给窗口的大小这个属性,从而实现图表对象与窗口对象的尺寸一致的情况
window.onresize = echart.resize*0.8;
echart.setOption(option);
} }

  

效果:

利用js来画图形(例如:条状图,圆饼图等)的更多相关文章

  1. HighCharts之2D堆条状图

    HighCharts之2D堆条状图 1.HighCharts之2D堆条状图源码 StackedBar.html: <!DOCTYPE html> <html> <head ...

  2. HighCharts之2D条状图

    HighCharts之2D条状图 1.HighCharts之2D条状图源码 bar.html: <!DOCTYPE html> <html> <head> < ...

  3. Excel 2010高级应用-条状图(五)

    Excel 2010高级应用-条状图(五) 基本操作如下: 1.新建一个Excel空白文档,并命名条状图 2.单击"插入",找到条状图的样图 3.选择其中一种类型的条状图样图,在空 ...

  4. Flex实现双轴条状图

    1.问题背景 一般的,柱状图可以实现双轴图,但是如何实现双轴条状图? 2.实现实例 <?xml version="1.0" encoding="utf-8" ...

  5. python中matplotlib绘图封装类之折线图、条状图、圆饼图

    DrawHelper.py封装类源码: import matplotlib import matplotlib.pyplot as plt import numpy as np class DrawH ...

  6. Matplotlib基本图形之饼状图

    Matplotlib基本图形之饼状图 饼状图特点: 饼状图显示一个数据系列中各项大小与各项总和的比例饼状图的数据点显示为整个饼状图的百分比 示例代码 import os import time imp ...

  7. d3.js(v5.7)树状图

    一.新建画布 二.数据处理 三.绘制连接线 图示: 四.绘制节点.文字 图示: 五.总结 path元素:其实就是定义了绘图的坐标点,从哪开始,移动到哪,怎样移动(命令) 具体可百度(或许以后我会总结一 ...

  8. maplotlib python 玩具绘图 横向纵向条状图

    from matplotlib import font_manager#解决zh-han图形汉字乱码 my_font = font_manager.FontProperties(fname=" ...

  9. MS Chart 条状图【转】

    private void Form1_Load(object sender, EventArgs e) {            string sql1 = "select  类别,coun ...

随机推荐

  1. Python的私有变量与装饰器@property的用法

    Python的私有变量是在变量前面加上双横杠(例如:__test)来标识, Python私有变量只能在类内部使用,不被外部调用,且当变量被标记为私有后,调用时需再变量的前端插入类名,在类名前添加一个下 ...

  2. ACM-ICPC 2018 南京赛区现场赛 K. Kangaroo Puzzle (思维+构造)

    题目链接:https://codeforc.es/gym/101981/attachments 题意:在 n * m 的平面上有若干个袋鼠和墙(1为袋鼠,0为墙),每次可以把所有袋鼠整体往一个方向移动 ...

  3. 多项式求逆入门 板题(Luogu P4238)

    下面是代码,推导详见 传送门 模板Code #include <cstdio> #include <cstring> #include <algorithm> us ...

  4. JavaScript基础05——严格模式

    严格模式: 除了正常运行模式,ECMAscript5添加了第二种运行模式:“严格模式”(strict mode).顾名思义,这种模式是的Javascript在更严格的条件下运行. 严格模式的作用: 1 ...

  5. check_monitor

    #! /bin/bash # 声明agent配置文件路径 CONF=/etc/sdata/zabbix/zabbix_agentd.conf #CONF=/tmp/zabbix_agentd.conf ...

  6. chmod/chown/chgrp/chattr

    权限组合其实就是二进制的组合 注意,用户只能修改属于自己的文件 仅管理员可以修改文件的数组和属主 chmod 三种使用方法 文件的特殊权限 SUID SGID Sticky chowm 修改文件,目录 ...

  7. ubuntu编译PCRE时出现 line 81: aclocal-1.14: command not found错误

    WARNING: 'aclocal-1.14' is missing on your system. You should only need it if you modified 'acinclud ...

  8. 查全率(Recall),查准率(Precision),灵敏性(Sensitivity),特异性(Specificity),F1,PR曲线,ROC,AUC的应用场景

    之前介绍了这么多分类模型的性能评价指标(<分类模型的性能评价指标(Classification Model Performance Evaluation Metric)>),那么到底应该选 ...

  9. 微信小程序 按钮固定在页面底部遮住页面显示内容问题

    我们分为以下部分来解决这个问题: 第一部分:问题的表现是怎么样的? 第二部分:问题的是如何实现的? 第三部分:如何解决问题? 第一部分:问题的表现是怎么样的? 我设置了页面有0-99共100个数,但是 ...

  10. hive 整合ranger

    一.安装hive插件 1.解压安装 #  tar zxvf ranger-2.0.0-SNAPSHOT-hive-plugin.tar.gz -C /data1/hadoop/ 2.修改install ...