以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]JSON数据 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=120309) |
-- 作者:ymjr2011 -- 发布时间:2018/6/12 14:54:00 -- [求助]JSON数据 echarts的 data数据构成 data:[ {value:335, name:\'直接访问\'}, {value:310, name:\'邮件营销\'}, {value:274, name:\'联盟广告\'}, {value:235, name:\'视频广告\'}, {value:400, name:\'搜索引擎\'} ] Dim Products As List(Of String) Products = DataTables("表A").GetValues("machineId","日期 >= \'" & d1 & "\' and 日期 < \'" & d1.AddDays(1) & "\'") Dim ii As Integer For Each Product As String In Products 想返回表A是machineid不重复的字段做为 name , 把表A的count(sumCycJob)做为 value Next 请问如何写?我写的都不对,只有一条数据! |
-- 作者:有点甜 -- 发布时间:2018/6/12 15:04:00 -- 直接合成字符串就可以了
Dim str As String = "" |
-- 作者:ymjr2011 -- 发布时间:2018/6/12 15:48:00 -- 解析出来好像有问题。 |
-- 作者:有点甜 -- 发布时间:2018/6/12 15:55:00 -- 1、你生成的字符串,最后是什么?
2、你在js里面获取得到字符串后,如何转换成json的?贴出代码。 |
-- 作者:ymjr2011 -- 发布时间:2018/6/12 16:07:00 -- Dim Products As List(Of String) Products = DataTables("表A").GetValues("machineId","日期 >= \'" & d1 & "\' and 日期 < \'" & d1.AddDays(1) & "\'") Dim jo As New JObject For Each Product As String In Products Dim count As String = DataTables("表A").compute("count(machineId)","machineid = \'" & product & "\' and 日期 >= \'" & d1 & "\' and 日期 < \'" & d1.AddDays(1) & "\'") str22 &= "{value:" & count & ", name:\'" & product & "\'}," Next str22 = str22.trim(",") JO("cpclfb") = "[" & str22 & "]" 以下是 option title : { text: \'某站点用户访问来源\', subtext: \'纯属虚构\', x:\'center\' }, tooltip : { trigger: \'item\', formatter: "{a} <br/>{b} : {c} ({d}%)" }, legend: { orient: \'vertical\', left: \'left\', data: [\'直接访问\',\'邮件营销\',\'联盟广告\',\'视频广告\',\'搜索引擎\'] }, series : [ { name: \'访问来源\', type: \'pie\', radius : \'55%\', center: [\'50%\', \'60%\'], data:mydata.cpclfb itemStyle: { emphasis: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: \'rgba(0, 0, 0, 0.5)\' } } } ] 以下JS var getData = function getData(){ var myChart2 = echarts.init(document.getElementById(\'chart_map\'), \'macarons\'); $.get(\'getdata.htm?type=1\').done(function (jsonstr) { var mydata = eval(\'(\' + jsonstr + \')\'); myChart2.setOption({ title : { text: \'来源\', subtext: \'纯属虚构\', x:\'center\' }, tooltip : { trigger: \'item\', formatter: "{a} <br/>{b} : {c} ({d}%)" }, legend: { orient: \'vertical\', left: \'left\', data: [\'直接访问\',\'邮件营销\',\'联盟广告\',\'视频广告\',\'搜索引擎\'] }, series : [ { name: \'访问来源\', type: \'pie\', radius : \'55%\', center: [\'50%\', \'60%\'], data:mydata.cpclfb itemStyle: { emphasis: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: \'rgba(0, 0, 0, 0.5)\' } } } ] }); }); setTimeout("getData()",2000); } setTimeout(function () { getData(); }, 2000); |
-- 作者:有点甜 -- 发布时间:2018/6/12 16:23:00 -- 如果要赋值给json,参考代码
Dim jo As New JObject
发送之前,请先弹出生成的json是否正确。 |
-- 作者:有点甜 -- 发布时间:2018/6/12 16:23:00 -- 如果你确实不会做,上传具体实例测试。 |
-- 作者:ymjr2011 -- 发布时间:2018/6/12 16:51:00 -- 谢谢好了: Dim Products As List(Of String) Products = DataTables("表A").GetValues("machineId","日期 >= \'" & d1 & "\' and 日期 < \'" & d1.AddDays(1) & "\'") jo("cpclfb") = ja Dim i As Integer =0 For Each product As String In products ja.add (new JObject) ja(i)("name") = product Dim ii As Integer = DataTables("表A").compute("count(machineId)","machineid = \'" & product & "\' and 日期 >= \'" & d1 & "\' and 日期 < \'" & d1.AddDays(1) & "\'") ja(i)("value")= ii i+=1 Next
|