Home >Backend Development >PHP Tutorial >关于echarts图表数据的转换,怎么输出固定格式得数据。

关于echarts图表数据的转换,怎么输出固定格式得数据。

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:21:512509browse

ECharts有下面两样数据

data:['直接访问','邮件营销','联盟广告','视频广告','搜索引擎']

data:[
                {value:335, name:'直接访问'},
                {value:310, name:'邮件营销'},
                {value:234, name:'联盟广告'},
                {value:135, name:'视频广告'},
                {value:1548, name:'搜索引擎'}
            ]

我从数据库中读取到相应数据后,怎么转换成上面得两种格式呢??

求大神指教。


回复讨论(解决方案)

没看懂你想表达什么,能否贴出你要取出的数据表?

$rs = mysql_query("select value对应字段名 as value, name对应字段名 as name from 表");
while($r = mysql_fetch_assoc($rs)) {
  $d1[] = $r[['name'];
  $d2[] = $r;
}

$d1、$d2 就是你要的两个数组,返还给 echarts 时按要求做 json_encode

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn