登录  /  注册

echarts 通过php 动态填充数据,请赐教,谢谢!

php中文网
发布: 2016-06-23 13:26:13
原创
1126人浏览过

我的显示页面:

  <script type="text/javascript">         function xName()		 {				var arr=new Array();				$.ajax(				{					url:"http://localhost:8080/POS/dbfun/report.db.php",					dataType:"json",					async:false,					success:function(data)					{						//调用函数获取值,转换成数组模式												 //var ss=eval(data);						 // alert(111);						 //for(var i=0;i<ss.length;i++)						 //{						 //  arr.push(ss[i].day);						 //  alert(arr[i]);						 //}                         //var ss=data[0].day;						 //alert(ss);				    },					timeout: 5000,                      error: function (XMLHttpRequest, textStatus, errorThrown) 						{                                                 alert(errorThrown); 						}				 				});				return arr;		}               // 路径配置        require.config({            paths:{                 'echarts' : '../echarts/ejs/echarts',                'echarts/chart/pie' : '../echarts/ejs/echarts'            }        });                        // 使用        require(            [                'echarts',                'echarts/chart/pie',				'echarts/chart/bar' // 使用柱状图就加载bar模块,按需加载            ],            function (ec) {                // 基于准备好的dom,初始化echarts图表                var myChart = ec.init(document.getElementById('main'));                                 //option = {                //	    title : {                //	        text: '某站点用户访问来源',               // 	        subtext: '纯属虚构',               // 	        x:'center'               // 	    },               // 	    tooltip : {               // 	        trigger: 'item',               // 	        formatter: "{a} <br/>{b} : {c} ({d}%)"               // 	    },               // 	    legend: {               // 	        orient : 'vertical',               // 	        x : 'left',               // 	        data:['直接访问','邮件营销','联盟广告','视频广告','搜索引擎']               // 	    },                //	    toolbox: {                //	        show : true,                //	        feature : {               // 	            mark : {show: true},               // 	            dataView : {show: true, readOnly: false},               // 	            restore : {show: true},               // 	            saveAsImage : {show: true}               // 	        }               // 	    },               // 	    calculable : true,               // 	    series : [               // 	        {               // 	            name:'访问来源',               // 	            type:'pie',               // 	            radius : '55%',               // 	            center: ['50%', '60%'],               // 	            data:[               // 	                {value:335, name:'直接访问'},               // 	                {value:310, name:'邮件营销'},               // 	                {value:234, name:'联盟广告'},               // 	                {value:135, name:'视频广告'},               // 	                {value:1548, name:'搜索引擎'}               // 	            ]               // 	        }               // 	    ]               // 	};               			   option = {					title : {						text: '某地区蒸发量和降水量',						subtext: '纯属虚构'					},					tooltip : {						trigger: 'axis'					},					legend: {						data:['蒸发量','降水量']					},					toolbox: {						show : true,						feature : {							mark : {show: true},							dataView : {show: true, readOnly: false},							magicType : {show: true, type: ['line', 'bar']},							restore : {show: true},							saveAsImage : {show: true}						}					},					calculable : true,					xAxis : [						{							type : 'category',							data : ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']						}					],					yAxis : [						{							type : 'value'						}					],					series : [						{							name:'蒸发量',							type:'bar',							data:[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],							markPoint : {								data : [									{type : 'max', name: '最大值'},									{type : 'min', name: '最小值'}								]							},							markLine : {								data : [									{type : 'average', name: '平均值'}								]							}						},						{							name:'降水量',							type:'bar',							data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],							markPoint : {								data : [									{name : '年最高', value : 182.2, xAxis: 7, yAxis: 183, symbolSize:18},									{name : '年最低', value : 2.3, xAxis: 11, yAxis: 3}								]							},							markLine : {								data : [									{type : 'average', name : '平均值'}								]							}						}					]				};                // 为echarts对象加载数据                 myChart.setOption(option);             }        );         </script>
登录后复制


这个链接:
http://localhost:8080/POS/dbfun/report.db.php
获取的数据格式是json
[{"total":"167","day":"20"},{"total":"650","day":"21"}]
登录后复制


请问我需要怎么修改代码,让数据能填充到echars 里面去,谢谢!


回复讨论(解决方案)

我的$.ajax 怎么不执行,没有进入success  也没报错,请问是怎么回事?

http://ask.csdn.net/questions/161294#answer_30688

我也想知道这个问题的答案,不知道楼主有没有解决,求解决方案476926020@qq.com,谢谢了

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
关于CSS思维导图的课件在哪? 课件
凡人来自于2024-04-16 10:10:18
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号