2014-11-21 8 views
0

DataTable에 Json 개체가 채워진 Google 원형 차트를 그릴 수 없습니다.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; 
} 

아이템 등급이 표시되지 않는 이유

<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> 

어떤 사람이 나에게 설명해 주시겠습니까

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. 감사.

답변

0

json을 보지 않고 이것이 유일한 오류인지 말하기는 어렵습니다. 하지만 콜백 함수가 올바르게 지정되지 않았습니다. 이을 변경해야합니다 : 여기에

google.setOnLoadCallback(drawChart); 

:

google.setOnLoadCallback(drawPieChart); 

당신이 HTML로 데이터를 결혼 지정한 기능을해야 setOnLoadCallback에 전달하는 인수입니다. 이 경우는 drawPieChart입니다.

관련 문제