您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“如何將字符串JSON轉(zhuǎn)換成符合格式的數(shù)據(jù)”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
<!DOCTYPE html> <html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"> <head> <th:block th:include="include :: header('線狀圖')" /> </head> <body class="gray-bg"> <span id="sparkline19"></span> <span class="line" id="sparkline201"></span> <!-- 為ECharts準(zhǔn)備一個(gè)具備大?。▽捀撸┑腄om --> <div id="main" class="line" ></div> <th:block th:include="include :: footer" /> <th:block th:include="include :: sparkline-js" /> <script th:inline="javascript"> $(function () { var id = [[${id}]] $.ajax({ type: "post", url: ctx + "user/mapping", data: { }, success: function(r) { //alert(r) var str = []; var str2 = []; var str3 = []; var str4 = []; console.log(r.data); str=JSON.parse("[" + r.data + "]"); str3=r.data; str4=r.data; console.log(str4); for (i=0;i<str.length;i++ ) { str2.push(str[i]); } console.log(str2); var mapResult2 = str2.map(function(item,index,array){ return item-0; }); $("#sparkline9").sparkline(mapResult2, { type: 'line', lineWidth: 1, height: '300px', lineColor: '#17997f', fillColor: '#ffffff', }); $("#sparkline19").sparkline([mapResult2], { type: 'line', lineWidth: 1, height: '300px', lineColor: '#17997f', fillColor: '#ffffff', }); // 基于準(zhǔn)備好的dom,初始化echarts實(shí)例 var myChart = echarts.init(document.getElementById('main')); // 指定圖表的配置項(xiàng)和數(shù)據(jù) var option = { title: { text: '折線圖堆疊' }, tooltip: { trigger: 'axis' }, legend: { data: ['郵件營銷', '聯(lián)盟廣告', '視頻廣告'] }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, toolbox: { feature: { saveAsImage: {} } }, xAxis: { type: 'category', boundaryGap: false, data: [] }, yAxis: { type: 'value' }, series: [ { name: '郵件營銷', type: 'line', stack: '總量', data: [mapResult2] }, { name: '郵件營銷11', type: 'line', stack: '總量', data: mapResult2 } ] } // 使用剛指定的配置項(xiàng)和數(shù)據(jù)顯示圖表。 myChart.setOption(option); } }) }); </script> </body> </html>
<!DOCTYPE html> <html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"> <head> <th:block th:include="include :: header('線狀圖')" /> </head> <body class="gray-bg"> <span id="sparkline19"></span> <span class="line" id="sparkline201"></span> <!-- 為ECharts準(zhǔn)備一個(gè)具備大小(寬高)的Dom --> <div id="main" class="line" ></div> <th:block th:include="include :: footer" /> <th:block th:include="include :: sparkline-js" /> <script th:inline="javascript"> $(function () { var id = [[${id}]] $.ajax({ type: "post", url: ctx + "user/mapping", data: { }, success: function(r) { //alert(r) var str = []; var str2 = []; var str3 = []; var str4 = []; console.log(r.data); str=JSON.parse("[" + r.data + "]"); str3=r.data; str4=r.data; console.log(str4); for (i=0;i<str.length;i++ ) { str2.push(str[i]); } console.log(str2); var mapResult2 = str2.map(function(item,index,array){ return item-0; }); $("#sparkline9").sparkline(mapResult2, { type: 'line', lineWidth: 1, height: '300px', lineColor: '#17997f', fillColor: '#ffffff', }); $("#sparkline19").sparkline([mapResult2], { type: 'line', lineWidth: 1, height: '300px', lineColor: '#17997f', fillColor: '#ffffff', }); // 基于準(zhǔn)備好的dom,初始化echarts實(shí)例 var myChart = echarts.init(document.getElementById('main')); // 指定圖表的配置項(xiàng)和數(shù)據(jù) var option = { title: { text: '折線圖堆疊' }, tooltip: { trigger: 'axis' }, legend: { data: ['郵件營銷', '聯(lián)盟廣告', '視頻廣告'] }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, toolbox: { feature: { saveAsImage: {} } }, xAxis: { type: 'category', boundaryGap: false, data: [] }, yAxis: { type: 'value' }, series: [ { name: '郵件營銷', type: 'line', stack: '總量', data: [mapResult2] }, { name: '郵件營銷11', type: 'line', stack: '總量', data: mapResult2 } ] } // 使用剛指定的配置項(xiàng)和數(shù)據(jù)顯示圖表。 myChart.setOption(option); } }) }); </script> </body> </html>
關(guān)鍵處理代碼
var mapResult2 = str2.map(function(item,index,array){ return item-0; });
“如何將字符串JSON轉(zhuǎn)換成符合格式的數(shù)據(jù)”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。