0
我無法繪製Google餅圖,它有一個由Json對象填充的DataTable
。Json對象到Google餅圖
這是我的代碼來生成數據對象(從我的代碼背後)。
public string getJsonObj()
{
Utility utils = new Utility();
List<Item> dataList = new List<Item>();
dataList.Add(new Item("Mosta",50));
dataList.Add(new Item("Naxxar",60));
string json = utils.JsonString(dataList);
this.ChartData.Value = json;
return json;
}
項目類
public class Item
{
private string location = "";
private int frequency = 0;
public Item(string location, int frequency)
{
this.Location = location;
this.Frequency = frequency;
}
public string Location
{
get { return location; }
set { location = value; }
}
public int Frequency
{
get { return frequency; }
set { frequency = value; }
}
}
HTML
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawChart);
<script type="text/javascript">
function drawPieChart() {
var data = google.visualization.DataTable(document.getElementById("ChartData").value));
var options = {
title: 'Test Pie Chart'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart1'));
chart.draw(data, options);
}
</script>
<div id="piechart1" style="width: auto; height: auto;"></div>
可有人請向我解釋這是爲什麼不顯示。謝謝。