基于echarts实现图表展示
2015-10-13 11:26
246 查看
[Author]: kwu
基于echarts实现图表展示
1、引用相关的js框架
[javascript] view
plaincopy
<pre name="code" class="javascript"><script type="text/javascript" src="js/esl/esl.js"></script>
<script type="text/javascript" src="js/echarts.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
2、创建一个div用来展示图表,需给定高度
[html] view
plaincopy
<div id="main" style="height:800px"></div>
3、配置路径及js的引用
[javascript] view
plaincopy
// 路径配置
require.config({
paths: {
echarts: 'js'
}
});
// 使用
require(
[
'echarts',
'echarts/chart/bar',
'echarts/chart/line'
],
4、主要的js代码,这里实现的是一个堆积图
[javascript] view
plaincopy
var option = {
//设置标题
title:{
text:'',
subtext:''
},
tooltip : {
trigger: 'axis',
axisPointer : { // 坐标轴指示器,坐标轴触发有效
type : 'shadow' // 默认为直线,可选为:'line' | 'shadow'
}
},
legend: {
data:[]
},
toolbox: {
show : true,
feature : {
mark : {show: true},
dataView : {show: true, readOnly: false},
magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
restore : {show: true},
saveAsImage : {show: true}
}
},
calculable : true,
yAxis : [
{
type : 'value'
}
],
xAxis : [
{
type : 'category',
data : []
}
],
series : [
{
name:'',
type:'bar',
stack: '总量',
itemStyle : { normal: {label : {show: true, position: 'insideRight'}}},
data:[]
},
{
name:'',
type:'bar',
stack: '总量',
itemStyle : { normal: {label : {show: true, position: 'insideRight'}}},
data:[]
},
{
name:'',
type:'bar',
stack: '总量',
itemStyle : { normal: {label : {show: true, position: 'insideRight'}}},
data:[]
},
{
name:'',
type:'bar',
stack: '总量',
itemStyle : { normal: {label : {show: true, position: 'insideRight'}}},
data:[]
},
{
name:'',
type:'bar',
stack: '总量',
itemStyle : { normal: {label : {show: true, position: 'insideRight'}}},
data:[]
},
{
name:'',
type:'bar',
stack: '总量',
itemStyle : { normal: {label : {show: true, position: 'insideRight'}}},
data:[]
}
]
};
5、采用ajax动态加载数据
[javascript] view
plaincopy
$.ajax({
type:'get',//jquey是不支持post方式跨域的
async:false,
url:"http://10.130.2.245:9088/dailyAll?limit=25", //跨域请求的URL
dataType:'jsonp',
jsonp: "callback",//服务端用于接收callback调用的function名的参数
success : function(result){
if (result) {
option.title.text = "("+result.titles+")堆积图";
option.title.subtext = result.titles;
option.legend.data = result.titles;
option.xAxis[0].data = result.days;
option.series[0].name = result.titles[0];
option.series[0].data = result.pvcnts;
option.series[1].name = result.titles[1];
option.series[1].data = result.hundsuncnts;
option.series[2].name = result.titles[2];
option.series[2].data = result.apputrackcnts;
option.series[3].name = result.titles[3];
option.series[3].data = result.utrackcnts;
option.series[4].name = result.titles[4];
option.series[4].data = result.mobilelogcnts;
option.series[5].name = result.titles[5];
option.series[5].data = result.dratiocnts;
myChart.setOption(option);
}
},
error:function(){
alert('fail');
}
});
ajax通过restful的服务来交互数据,相关restful的开发,请参考本博客:
http://blog.csdn.net/bdchome/article/details/45937751
实现的效果图:
基于echarts实现图表展示
1、引用相关的js框架
[javascript] view
plaincopy
<pre name="code" class="javascript"><script type="text/javascript" src="js/esl/esl.js"></script>
<script type="text/javascript" src="js/echarts.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
2、创建一个div用来展示图表,需给定高度
[html] view
plaincopy
<div id="main" style="height:800px"></div>
3、配置路径及js的引用
[javascript] view
plaincopy
// 路径配置
require.config({
paths: {
echarts: 'js'
}
});
// 使用
require(
[
'echarts',
'echarts/chart/bar',
'echarts/chart/line'
],
4、主要的js代码,这里实现的是一个堆积图
[javascript] view
plaincopy
var option = {
//设置标题
title:{
text:'',
subtext:''
},
tooltip : {
trigger: 'axis',
axisPointer : { // 坐标轴指示器,坐标轴触发有效
type : 'shadow' // 默认为直线,可选为:'line' | 'shadow'
}
},
legend: {
data:[]
},
toolbox: {
show : true,
feature : {
mark : {show: true},
dataView : {show: true, readOnly: false},
magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
restore : {show: true},
saveAsImage : {show: true}
}
},
calculable : true,
yAxis : [
{
type : 'value'
}
],
xAxis : [
{
type : 'category',
data : []
}
],
series : [
{
name:'',
type:'bar',
stack: '总量',
itemStyle : { normal: {label : {show: true, position: 'insideRight'}}},
data:[]
},
{
name:'',
type:'bar',
stack: '总量',
itemStyle : { normal: {label : {show: true, position: 'insideRight'}}},
data:[]
},
{
name:'',
type:'bar',
stack: '总量',
itemStyle : { normal: {label : {show: true, position: 'insideRight'}}},
data:[]
},
{
name:'',
type:'bar',
stack: '总量',
itemStyle : { normal: {label : {show: true, position: 'insideRight'}}},
data:[]
},
{
name:'',
type:'bar',
stack: '总量',
itemStyle : { normal: {label : {show: true, position: 'insideRight'}}},
data:[]
},
{
name:'',
type:'bar',
stack: '总量',
itemStyle : { normal: {label : {show: true, position: 'insideRight'}}},
data:[]
}
]
};
5、采用ajax动态加载数据
[javascript] view
plaincopy
$.ajax({
type:'get',//jquey是不支持post方式跨域的
async:false,
url:"http://10.130.2.245:9088/dailyAll?limit=25", //跨域请求的URL
dataType:'jsonp',
jsonp: "callback",//服务端用于接收callback调用的function名的参数
success : function(result){
if (result) {
option.title.text = "("+result.titles+")堆积图";
option.title.subtext = result.titles;
option.legend.data = result.titles;
option.xAxis[0].data = result.days;
option.series[0].name = result.titles[0];
option.series[0].data = result.pvcnts;
option.series[1].name = result.titles[1];
option.series[1].data = result.hundsuncnts;
option.series[2].name = result.titles[2];
option.series[2].data = result.apputrackcnts;
option.series[3].name = result.titles[3];
option.series[3].data = result.utrackcnts;
option.series[4].name = result.titles[4];
option.series[4].data = result.mobilelogcnts;
option.series[5].name = result.titles[5];
option.series[5].data = result.dratiocnts;
myChart.setOption(option);
}
},
error:function(){
alert('fail');
}
});
ajax通过restful的服务来交互数据,相关restful的开发,请参考本博客:
http://blog.csdn.net/bdchome/article/details/45937751
实现的效果图:
相关文章推荐
- Swift2.1 语法指南——构造过程
- 架构之路(五):忘记数据库
- substring方法的使用
- 使用JDBC的addBatch()方法提高数据库插入更新效率
- Excel-VBA操作文件四大方法之一
- prepareStatement与Statement的区别
- bzoj2820: YY的GCD
- 全国五大热招行业公布 看看哪家最有“钱”
- gdb多线程调试
- Java从入门到精通11-异常
- 关于C++中的虚拟继承的一些总结
- 电快速脉冲群EFT(概念)
- 文章标题
- CodeForces 527C(set大法好)
- 测试文章发布问题
- 基于VRRP协议的Keepalived原理详解
- Java中tomcat memecached session 共享同步问题的解决办法
- Linux(CentOS)下安装配置和使用PostgreSQL数据库
- 下拉框处理后台list
- 【学习笔记】系列九:接口测试