2012-06-18 92 views
1

數據我是新的網頁設計,我試圖填充用C#從SQL數據庫中的數據highcharts餅圖。我已經成功完成了條形圖,但在餅圖上遇到了麻煩。基本上我有一個表tblReport1,其中包含2個字段CustomerType和TotalOrdersHighCharts填充餅圖與SQL數據庫

我可以得到它帶來的價值,但我不能讓我的切片重命名爲CustomerType字段中的數據。我已經在這個論壇上嘗試了幾個建議,但無法讓他們工作。以下是我的代碼,任何建議將不勝感激。

private void Report1() 
{ 
    dsSeries = BindData(); 

    if (dsSeries == null) return; 

    foreach (DataRow dr in dsSeries.Tables[0].Rows) 
    { 
     hidXCategories11.Add(dr["CustomerType"]); 
    } 

    foreach (DataRow dr1 in dsSeries.Tables[0].Rows) 
    { 
     hidValues11.Add(Convert.ToInt32(dr1["TotalOrders"])); 
     yValues = hidValues11.ToArray(typeof(object)) as object[]; 
    } 


    DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart") 
    .InitChart(new Chart { PlotShadow = false }) 
    .SetTitle(new Title { Text = "Orders by Customer Type" }) 
    .SetTooltip(new Tooltip { Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.y +' Orders'; }" }) 
    .SetPlotOptions(new PlotOptions 
    { 
     Pie = new PlotOptionsPie 
     { 
      ShowInLegend = true, 
      AllowPointSelect = true, 
      DataLabels = new PlotOptionsPieDataLabels 
      { 
       Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.y; }" 
      } 
     } 
    }) 

    .SetSeries(new[] 
     { 
       new Series { Type = ChartTypes.Pie, Name = "help!", Data = new Data(yValues) } 
     }); 



    ltrChart.Text = chart.ToHtmlString(); 

} 
+0

你可以忍受發送給客戶端的javscript的樣子嗎?這是.NET代碼(我甚至不知道有.NET接口),但「真正的」高位代碼都運行在客戶端。一目瞭然,您看起來像是在設置正確的選項,但是更容易檢查我們是否可以在JavaScript中看到真正的選項。 – Chris

+0

嗨克里斯我沒有JavaScript的只是一個部分我的aspx文件中的和我鏈接到highchart.js文件 – bsmith

+0

@bsmith,你可以看看你的文字標籤應該在的位置的「實時」頁面,然後告訴我們這個javascript是什麼? .NET highcharts API創建一個它寫入的文字標籤(它實際上只是創建一串javascript並將其放入文字標籤中 - 或多或少)。 – wergeld

回答

2

http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/pie-basic/尋找餅圖數據格式爲兩個部分,標籤和數據項。

在你的樣子該系列數據爲整數的只是一個單一的陣列。

所以我認爲你需要改變你的Series對象來接受數據的不同格式。

可悲的是Highcharts.Net文檔中的例子是有點欠缺,做似乎沒有這方面的例子,所以你可能要看看智能感知所提供的。

底線是,雖然你的餡餅楔子需要在數據系列被命名,而不是作爲類別或其他任何東西。

編輯了一些示例代碼

我看他們的網站,他們有一個幫助論壇那裏當中它

 series.Add(new Serie 
     { 
      data = new object[] { 
       new object[] { "Firefox", 45 }, 
       new object[] { "IE", 24.8 }, 
       new object[] { "Chrome", 12.8 }, 
       new object[] { "Safari", 8.5 }, 
       new object[] { "Opera", 5.2 }, 
       new object[] { "Outros", 3.7 } 
      } 
     }); 

源下面的示例代碼:http://highcharts.codeplex.com/discussions/269347

我不能測試這個,但從帖子的上下文看,它應該做這項工作。

+0

對於數據值我使用數據類型對象來存儲值你知道我需要使用的切片名稱。我已經嘗試了一個數組列表和字符串,但都沒有工作 – bsmith

+0

@bsmith:你可以發佈一些工作代碼..你接受這個答案 – RealSteel