背景: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. 36大数据和about云的文章总结

    36大数据: 白话机器学习 http://www.36dsj.com/archives/78385 基于Hadoop的数据仓库Hive 基础知识(写的很好) http://www.36dsj.com/ ...

  2. SpringBoot整合Bubbo

    一.创建springboot_dubbo_provider项目 1 创建service层接口 public interface IDoSomeService { public String sayHi ...

  3. 学习Spring-Data-Jpa(十四)---自定义Repository

    有些时候,我们需要自定义Repository实现一些特殊的业务场景. 1.自定义单个Repository 1.1.首先提供一个片段接口和实现(接口的实现默认要使用Impl为后缀,实现本身不依赖spri ...

  4. go 学习 (二):基本语法

    一.数据类型 布尔型:布尔型的值只可以是常量 true 或者 false.eg:var bo bool = true.布尔型无法参与数值运算,也无法与其他类型进行转换 数字类型:整型 int .浮点型 ...

  5. BZOJ 5082: 弗拉格 矩阵乘法

    如果单点而不是求 sigma 的话还是比较好办的. 遇到这种前缀和相减的矩阵乘法可以增设一个 0 使得后面的能先加到前面,然后再算. 这样的话可以使的最后算出的是前缀和相加的形式. code: #in ...

  6. 洛谷P4047 [JSOI2010]部落划分题解

    洛谷P4047 [JSOI2010]部落划分题解 题目描述 聪聪研究发现,荒岛野人总是过着群居的生活,但是,并不是整个荒岛上的所有野人都属于同一个部落,野人们总是拉帮结派形成属于自己的部落,不同的部落 ...

  7. 玩家属性同步优化-脏数据标记(位运算、数组、stl之bitset)

    把大神的帖子中一部分摘抄出来,结合自己写的位运算代码和循环代码(数组遍历)进行性能测试分析并给出结果. 摘自: https://www.gameres.com/827195.html 本文适用于所有脏 ...

  8. C++通过迭代修改字符串本身(auto类型说明符)

    以字符串这种支持 for (declaration : expression) statement 这样for语句迭代的数据结构为例,我们看看auto关键字在类型推断中的作用. string s = ...

  9. python中的base64加密解密

    介绍 Base64是网络上最常见的用于传输8Bit字节码的编码方式之一,Base64就是一种基于64个可打印字符来表示二进制数据的方法.可查看RFC2045-RFC2049,上面有MIME的详细规范. ...

  10. docker容器启动后添加端口映射

    DOCKER 给运行中的容器添加映射端口 方法1 1.获得容器IP 将container_name 换成实际环境中的容器名 docker inspect `container_name` | grep ...