您好,登錄后才能下訂單哦!
本篇內容介紹了“如何將字符串JSON轉換成符合格式的數據”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
<!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準備一個具備大小(寬高)的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', }); // 基于準備好的dom,初始化echarts實例 var myChart = echarts.init(document.getElementById('main')); // 指定圖表的配置項和數據 var option = { title: { text: '折線圖堆疊' }, tooltip: { trigger: 'axis' }, legend: { data: ['郵件營銷', '聯盟廣告', '視頻廣告'] }, 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 } ] } // 使用剛指定的配置項和數據顯示圖表。 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準備一個具備大小(寬高)的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', }); // 基于準備好的dom,初始化echarts實例 var myChart = echarts.init(document.getElementById('main')); // 指定圖表的配置項和數據 var option = { title: { text: '折線圖堆疊' }, tooltip: { trigger: 'axis' }, legend: { data: ['郵件營銷', '聯盟廣告', '視頻廣告'] }, 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 } ] } // 使用剛指定的配置項和數據顯示圖表。 myChart.setOption(option); } }) }); </script> </body> </html>
關鍵處理代碼
var mapResult2 = str2.map(function(item,index,array){ return item-0; });
“如何將字符串JSON轉換成符合格式的數據”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。