{"id":1848,"date":"2019-07-17T08:36:04","date_gmt":"2019-07-17T00:36:04","guid":{"rendered":"http:\/\/www.hefeiyu.com\/?p=1848"},"modified":"2019-07-17T08:36:04","modified_gmt":"2019-07-17T00:36:04","slug":"ecology%e5%bc%80%e5%8f%91%e4%b9%8bjquery-amcharts%e7%bb%84%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/www.hefeiyu.com\/?p=1848","title":{"rendered":"ecology\u5f00\u53d1\u4e4bjquery-amcharts\u7ec4\u4ef6"},"content":{"rendered":"<table width=\"1112\">\n<tbody>\n<tr>\n<td width=\"72\">\u7ec4\u4ef6<\/td>\n<td colspan=\"3\" width=\"1040\">jquery-amcharts\u7ec4\u4ef6\uff08\u56fe\u72b6\u7ec4\u4ef6\uff09<\/td>\n<\/tr>\n<tr>\n<td>\u529f\u80fd\u8bf4\u660e<\/td>\n<td colspan=\"3\" width=\"1040\">\u57fa\u4e8ejQuery\u73af\u5f62\u56fe\u72b6\u63a7\u4ef6\uff0c\u5176\u7279\u70b9\u5982\u4e0b\uff1a<br \/>\n\u4ee5\u5404\u79cd\u56fe\u5f62\u5316\u6a21\u5f0f\u663e\u793a\u6570\u636e\uff0c\u76f4\u89c2\u3002<\/td>\n<\/tr>\n<tr>\n<td rowspan=\"2\">\u4f7f\u7528\u8bf4\u660e<\/td>\n<td colspan=\"3\" width=\"1040\">1.\u5f15\u5165\u5982\u4e0bjs<br \/>\n\u5982\u679c\u6ca1\u6709\u5f15\u5165\u4ee5\u4e0bjs\uff0c\u90a3\u4e48\u9700\u8981\u5f15\u5165\u4ee5\u4e0bjs\uff1a<br \/>\n&lt;script src=&#8221;\/js\/jquery-amcharts\/amcharts\/amcharts_wev8.js&#8221; type=&#8221;text\/javascript&#8221;&gt;&lt;\/script&gt;<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\" width=\"1040\">2\u3001\u9875\u9762\u6307\u5b9a\u4e00\u4e2a\u663e\u793a\u533a\u57df<br \/>\n&lt;div id=&#8221;chartdiv&#8221; style=&#8221;width: 300px; height: 400px;&#8221;&gt;&lt;\/div&gt;<br \/>\n3\u3001\u5f53\u9875\u9762\u52a0\u8f7d\u5b8c\u6210\u540e\uff0c\u5728\u9875\u9762\u4e0a\u8c03\u7528\u5982\u4e0b\u65b9\u6cd5<br \/>\n$(document).ready(function() {<br \/>\n$.ajax({<br \/>\ntype: &#8220;GET&#8221;,<br \/>\nurl: &#8220;\u8fdc\u7a0b\u5730\u5740\u5982:http:\/\/localhost:8080\/amchartdata.action&#8221;,<br \/>\nsuccess: function(msg){<br \/>\n\/\/\u8fd9\u91cc\u8ba4\u4e3amsg\u4e3ajson\u5bf9\u8c61<br \/>\n\/\/\u9700\u8981\u5c06json\u5bf9\u8c61\u8f6c\u6362\u6210\u7c7b\u4f3c\u4e0a\u9762\u7684chartData\u53d8\u91cf\u7684\u6570\u7ec4<br \/>\nvar list = [];<br \/>\nfor(var k in msg){<br \/>\nvar data = {};<br \/>\nfor(var k2 in msg[k]){<br \/>\ndata[k2] = msg[k][k2];<br \/>\n}<br \/>\nlist.push(data);<br \/>\n}<\/p>\n<p>chartData = list;<br \/>\ncreateChart();<br \/>\n}<br \/>\n});<br \/>\n\/\/\u5982\u679c\u662f\u9759\u6001\u7684\u6570\u636e\uff0c\u76f4\u63a5\u8c03\u7528createChart();\u4f7f\u7528chartData\u53d8\u91cf\u3002\u4e0a\u9762\u7684\u8fdc\u7a0b\u8c03\u7528\u53bb\u6389\u3002<br \/>\n\/\/createChart();<br \/>\n});<br \/>\n\/\/\u521b\u5efa\u67f1\u72b6\u56fe<br \/>\nfunction createChart(){<br \/>\n\/\/ SERIAL CHART<br \/>\nchart = new AmCharts.AmSerialChart();<br \/>\nchart.dataProvider = chartData;<br \/>\nchart.categoryField = &#8220;year&#8221;;<br \/>\n\/\/ this single line makes the chart a bar chart,<br \/>\n\/\/ try to set it to false &#8211; your bars will turn to columns<br \/>\nchart.rotate = true;<br \/>\n\/\/ the following two lines makes chart 3D<br \/>\nchart.depth3D = 20;<br \/>\nchart.angle = 30;<\/p>\n<p>\/\/ AXES<br \/>\n\/\/ Category<br \/>\nvar categoryAxis = chart.categoryAxis;<br \/>\ncategoryAxis.gridPosition = &#8220;start&#8221;;<br \/>\ncategoryAxis.axisColor = &#8220;#DADADA&#8221;;<br \/>\ncategoryAxis.fillAlpha = 1;<br \/>\ncategoryAxis.gridAlpha = 0;<br \/>\ncategoryAxis.fillColor = &#8220;#FAFAFA&#8221;;<\/p>\n<p>\/\/ value<br \/>\nvar valueAxis = new AmCharts.ValueAxis();<br \/>\nvalueAxis.axisColor = &#8220;#DADADA&#8221;;<br \/>\nvalueAxis.title = &#8221; xx\u7edf\u8ba1\u56fe&#8221;;<br \/>\nvalueAxis.gridAlpha = 0.1;<br \/>\nchart.addValueAxis(valueAxis);<\/p>\n<p>\/\/ GRAPH<br \/>\nvar graph = new AmCharts.AmGraph();<br \/>\ngraph.title = &#8220;Income&#8221;;<br \/>\ngraph.valueField = &#8220;income&#8221;;<br \/>\ngraph.type = &#8220;column&#8221;;<br \/>\n\/\/graph.balloonText = &#8220;Income in [[category]]:[[value]]&#8221;;<br \/>\ngraph.balloonText = &#8220;Income in [[category]]:[[value]]&#8221;;<br \/>\ngraph.lineAlpha = 0;<br \/>\ngraph.fillColors = &#8220;#bf1c25&#8221;;<br \/>\ngraph.fillAlphas = 1;<br \/>\nchart.addGraph(graph);<\/p>\n<p>\/\/ WRITE<br \/>\nchart.write(&#8220;chartdiv&#8221;);<br \/>\n}<\/td>\n<\/tr>\n<tr>\n<td>\u4f8b\u5b50<\/td>\n<td colspan=\"3\" width=\"1040\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"3\" width=\"1040\"><a href=\"http:\/\/www.amcharts.com\/demos\/\">http:\/\/www.amcharts.com\/demos\/<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<tr>\n<td>API<\/td>\n<td colspan=\"3\"><a href=\"http:\/\/docs.amcharts.com\/3\/\">http:\/\/docs.amcharts.com\/3\/<\/a><\/td>\n<\/tr>\n<tr>\n<td>\u5b98\u7f51<\/td>\n<td colspan=\"3\" width=\"1040\"><a href=\"http:\/\/www.amcharts.com\/\">http:\/\/www.amcharts.com\/<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"https:\/\/www.hefeiyu.com\">\u8d6b\u975e\u57df<\/a> &raquo; <a href=\"https:\/\/www.hefeiyu.com\/?p=1848\">ecology\u5f00\u53d1\u4e4bjquery-amcharts\u7ec4\u4ef6<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u7ec4\u4ef6 jquery-amcharts\u7ec4\u4ef6\uff08\u56fe\u72b6\u7ec4\u4ef6\uff09 \u529f\u80fd\u8bf4\u660e \u57fa\u4e8ejQuery\u73af\u5f62\u56fe\u72b6\u63a7\u4ef6\uff0c\u5176\u7279\u70b9\u5982\u4e0b\uff1a \u4ee5\u5404\u79cd\u56fe\u5f62\u5316\u6a21\u5f0f\u663e\u793a\u6570\u636e\uff0c\u76f4\u89c2\u3002 \u4f7f\u7528\u8bf4\u660e 1.\u5f15\u5165\u5982\u4e0bjs \u5982\u679c\u6ca1\u6709\u5f15\u5165\u4ee5\u4e0bjs\uff0c\u90a3\u4e48\u9700\u8981\u5f15\u5165\u4ee5\u4e0bjs\uff1a &lt;script src=&#038;# [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[611,100,102],"class_list":["post-1848","post","type-post","status-publish","format-standard","hentry","category-code","tag-amcharts","tag-jquery","tag-js"],"_links":{"self":[{"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=\/wp\/v2\/posts\/1848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1848"}],"version-history":[{"count":1,"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=\/wp\/v2\/posts\/1848\/revisions"}],"predecessor-version":[{"id":1849,"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=\/wp\/v2\/posts\/1848\/revisions\/1849"}],"wp:attachment":[{"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}