2013-12-17 75 views
1

我正在構建一個堆積柱形圖。我不知道進入它的系列的數量,因此我使用foreach來構建每個系列。我想爲每個系列分類標籤。通常對於像這樣的東西,我會使用類別表達式,但無法弄清楚如何以我正在構建的方式進行操作。這就是它看起來像沒有標籤的地方,只是爲了參考代碼。如何設置動態堆積柱形圖的分類標籤

enter image description here

任何幫助,將不勝感激。

@(Html.Kendo().Chart() 

.Name("chart") 

.Theme("flat") 

.Title("Issues Waterfall") 

.DataSource(ds => ds 

    .ServerOperation(false) 

) 

.Series(series => 

{ 

    series.Column(new double[] { 100 }).Name("Total").Color("Blue").Stack("Total"); 



    foreach (var resp in Model.listResponsibleDowntime) 

    { 

     series.Column(new double?[] { resp.percent_pad }).Name(resp.resp_name).Color("White").Opacity(0).Labels(false).Tooltip(false).Stack(resp.resp_name); 

     series.Column(new double?[] { resp.percent_downtime }).Name(resp.resp_name).Color(resp.resp_color).Labels(lables => lables.Format("{0:n2}%").Visible(true).Position(ChartBarLabelsPosition.OutsideEnd)).Stack(resp.resp_name); 

    } 



    series.Column(new double?[] { Model.oee }).Name("Actual").Color("Green").Stack("Actual").Labels(lables => lables.Format("{0:n2}%").Visible(true).Position(ChartBarLabelsPosition.OutsideEnd)); 



}) 

.CategoryAxis(axis => axis 

    .MajorGridLines(lines => lines.Visible(false)) 

    .Labels(model => model 

     .Rotation(0) 

     .Visible(true) 

    ) 

    //.Categories(Model.listCategories) 

) 

.Legend(legend => legend 

    .Position(ChartLegendPosition.Top) 

    .Margin(20, 50, 20, 50) 

    .Visible(false) 

) 

.ValueAxis(axis => axis 

    .Numeric() 

    .Min(0) 

    .Max(100) 

    .Labels(labels => labels.Format("{0:n0}%")) 

) 

.Tooltip(tooltip => tooltip 

    .Visible(true) 

    .Template("#= series.name #: #= kendo.format('{0:n2}', value) #") 

) 

回答

0

我知道這是舊的,但,這可能有助於在未來的人,因爲Telerik的文檔的習慣。

在你的foreach您需要通過列構建一個IEnumerable類,然後告訴它該字段是類別,這是值:

public class KendoStackedColumnModel 
    { 
     public string StackName { get; set; } 
     public string Colour { get; set; } 

     public IEnumerable<KendoColumnModel> Columns { get; set; } 

     public class KendoColumnModel 
     { 
      public decimal Value { get; set; } 
      public string Category { get; set; } 
     } 

    } 

而且在foreach:

series.Column(stacked.Columns).CategoryField("Category").Field("Value").Name(stacked.StackName).Color(stacked.Colour);