2013-02-05 74 views
0

我試圖生成一個像這樣的圖表:http://chartpart.com/但我不知道如何做到這一點。我是否需要生成手動生成圖表的字符串,或者是否需要發送數據到谷歌服務器和接收字符串?(如果是的話,我怎麼發送數據?) PS:我想在c#中做所有這些,並通過web服務發送結果字符串。使用Google圖表API生成圖表

回答

1

顯然你需要自己生成字符串。我這樣做,並通過web服務發送結果給android。

[WebMethod] 
     public ChartsClass GetChart(string UserId) 
     { 
      ChartsClass chart = new ChartsClass(); 
      DataSet1TableAdapters.WS_ChartIndicatorsTableAdapter adapter = new DataSet1TableAdapters.WS_ChartIndicatorsTableAdapter(); 
      DataSet1.WS_ChartIndicatorsDataTable table = adapter.GetChartIndicators(UserId); 

      StringBuilder sbDescriptions = new StringBuilder(); 
      StringBuilder sbValues = new StringBuilder(); 

      for(int i= 0 ;i< table.Rows.Count ;i++) 
      { 
       DataSet1.WS_ChartIndicatorsRow chartRow = (table.Rows[i] as DataSet1.WS_ChartIndicatorsRow); 
       if (i > 0) 
       { 
        sbDescriptions.Append("|"); 
        sbValues.Append(","); 
       } 

       sbDescriptions.Append(chartRow.SectorId + " - " + chartRow.SectorDescription); 
       sbValues.Append(chartRow.NetSaleValue.ToString()); 
      } 

      chart.ChartString = String.Format("http://chart.apis.google.com/chart?cht=p3&chtt={0}&chd=t:{1}&chs=480x200&chl={2}&chco=ff0000,0000ff", 
       "Live Sales", sbValues.ToString(), sbDescriptions.ToString()); 


      return chart; 
     } 

And android in you can load the result in a web view。

chartView = (WebView)findViewById(R.id.activity_chart_view); 
ChartsClass chart = new ChartsClass(soapObject); 
chartView.loadUrl(chart.chartStringSource);