我尝试使用flot chart生成条形图,我遇到了问题。
我的Json响应如下:
[{"label":"Total Sales",
"color":"#4345D1",
"data":"[['09-21-2016',3],['09-19-2016',1],['09-13-2016',2],
['10-21-2016',2]]"
}]
但是图表从未显示过,我想"数据"值可能包含双引号("), 如何转换它们,可以使用正确的格式,如下所示:
[{"label":"Total Sales",
"color":"#4345D1",
"data": [['09-21-2016',3],['09-19-2016',1],['09-13-2016',2],
['10-21-2016',2]]
}]
其他编码:
这是mysql查询数据源
select 'Total Sales' as label,
concat('[',group_concat("[",concat('\"',trxdate,'\"',",",qty),"]"),']')
as data
from(
select
DATE_FORMAT(trxdate,'%m-%d-%Y') as trxdate,
sum(quantity) as qty from Journals
group by
DATE_FORMAT(trxdate,'%m-%d-%Y')
) as A;
所以我将它们作为REST API放入nodejs,
然后是服务适配器:
$http({
method: 'GET',
url: vm.barsrc
}).then(
function successCallback(response) {
var datArr = response.data[0];
var datachart = ( datArr.data ).replace('"','').replace('"','');
var result = [
{
label: datArr.label,
color: datArr.color,
data: datachart
}
];
vm.StackedBarDataset = result;
}, function errorCallback(response) {
...
}
);
先谢谢你。
@derek: