我有一个带有一些图表的网页,我用java脚本用静态数据填充图表。我想用SQL数据替换静态数据。
我该怎么办?
这是我所拥有的一个例子。我不想写这样的数据值;我想从SQL服务器插入它。
var chart = AmCharts.makeChart("chartdiv", {
"theme": "light",
"type": "serial",
"startDuration": 2,
"dataProvider": [{
"country": "USA",
"visits": 4000,
"color": "#FF0F00"
}, {
"country": "China",
"visits": 1882,
"color": "#FF6600"
}, {
"country": "Japan",
"visits": 1809,
"color": "#FF9E01"
}, {
"country": "Germany",
"visits": 1322,
"color": "#FCD202"
}, {
"country": "UK",
"visits": 1122,
"color": "#F8FF01"
}, {
"country": "France",
"visits": 1114,
"color": "#B0DE09"
}, {
"country": "India",
"visits": 984,
"color": "#04D215"
}, {
"country": "Spain",
"visits": 711,
"color": "#0D8ECF"
}, {
"country": "Netherlands",
"visits": 665,
"color": "#0D52D1"
}, {
"country": "Russia",
"visits": 580,
"color": "#2A0CD0"
}, {
"country": "South Korea",
"visits": 443,
"color": "#8A0CCF"
}, {
"country": "Canada",
"visits": 441,
"color": "#CD0D74"
}, {
"country": "Brazil",
"visits": 395,
"color": "#754DEB"
}, {
"country": "Italy",
"visits": 386,
"color": "#DDDDDD"
}, {
"country": "Taiwan",
"visits": 338,
"color": "#333333"
}],
"valueAxes": [{
"position": "left",
"axisAlpha":0,
"gridAlpha":0
}],
"graphs": [{
"balloonText": "[[category]]: <b>[[value]]</b>",
"colorField": "color",
"fillAlphas": 0.85,
"lineAlpha": 0.1,
"type": "column",
"topRadius":1,
"valueField": "visits"
}],
"depth3D": 40,
"angle": 30,
"chartCursor": {
"categoryBalloonEnabled": false,
"cursorAlpha": 0,
"zoomable": false
},
"categoryField": "country",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha":0,
"gridAlpha":0
},
"export": {
"enabled": true
}
},0);
jQuery('.chart-input').off().on('input change',function() {
var property = jQuery(this).data('property');
var target = chart;
chart.startDuration = 0;
if ( property == 'topRadius') {
target = chart.graphs[0];
}
target[property] = this.value;
chart.validateNow();
});
#chartdiv {
width : 100%;
height : 435px;
font-size : 11px;
}
<div id="chartdiv"></div>
<div class="container-fluid">
<div class="row text-center" style="overflow:hidden;">
<div class="col-sm-3" style="float: none !important;display: inline-block;">
<label class="text-left">Top Radius:</label>
<input class="chart-input" data-property="topRadius" type="range" min="0" max="1.5" value="1" step="0.01"/>
</div>
<div class="col-sm-3" style="float: none !important;display: inline-block;">
<label class="text-left">Angle:</label>
<input class="chart-input" data-property="angle" type="range" min="0" max="89" value="30" step="1"/>
</div>
<div class="col-sm-3" style="float: none !important;display: inline-block;">
<label class="text-left">Depth:</label>
<input class="chart-input" data-property="depth3D" type="range" min="1" max="120" value="40" step="1"/>
</div>
</div>
</div>