2013-12-17 55 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);