[英]Populate google line chart by calling angularjs controller function from javascript code
我創建了一個 static 谷歌折線圖:
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
. var data = google.visualization.arrayToDataTable([
['Year', 'Massachusetts', 'National'],
['2010', 70, 76],
['2011', 89, 82],
['2012', 96, 86],
['2013', 100, 91],
['2014', null, 94],
['2015', null, 98],
['2016', 100, 99],
['2017', 124, 100],
['2018', 125, 102]
]);
var options = {
title: 'Average Home Insurance Premium',
curveType: 'function',
legend: { position: 'bottom' },
subtitle: 'in dollars (USD)',
vAxis: {
viewWindow: {
min: 0
}
},
width: 250,
height: 200,
sliceVisibilityThreshold: 0,
interpolateNulls:true
};
var chart = new google.visualization.LineChart(document.getElementById('fsm_container'));
chart.draw(data, options);
}
I have created a API to get data to create dynamic line chart and created a function in angularjs controller function.
$scope.getChartData = function () {
debugger;
$http.post('/Home/LineChartData?ZIP_CODE=' + '02111' + '&Lob=Homeowners').then(function (response) {
if (response.status == 200) {
var Jsondata = JSON.parse(response.data);
}
}
});
};
我想將 Jsondata(在上述函數中)傳遞給圖表並在那里顯示。 有沒有辦法從用於創建圖表的代碼中調用 function?
我使用了另一種方法。 我使用 ajax 調用並直接從這里打我的cs controller functuin 而不是調用 angularjs ZC14F14AB0.748E168A
$.ajax({
url: "LineChartData?ZIP_CODE=" + getUrlVars()["cal"] + "&Lob=Homeowners",
dataType: "json",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function (data) {}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.