2013-11-21 23 views
0

使用Dataviz和MVC,我想創建一個堆棧圖(這是工作)。但是我想只顯示系列標籤,如果該系列的值大於零。如何使系列標籤可見性有條件?

這裏是標記

@(Html.Kendo().Chart<ChartModel>(Model) 
    .Name("chart") 
    .Title("Pending Orders") 
    .Legend(legend => legend 
     .Visible(false) 
    ) 
    .SeriesDefaults(seriesDefaults => 
     seriesDefaults.Column().Stack(true) 
     .Labels(labels => labels.Background("transparent").Visible(true).Font("40px sans-serif").Position(ChartBarLabelsPosition.Center).Color("black")) 
    ) 
    .Series(series => 
    { 
     series.Column(model => model.OnTimeCount).Name("On Time").Color("Green"); 
     series.Column(model => model.WarningCount).Name("Warning").Color("Yellow"); 
     series.Column(model => model.AlertCount).Name("Alert").Color("Red"); 
    }) 

    .CategoryAxis(axis => axis 
     .Categories(model => model.Day) 
     .MajorGridLines(lines => lines.Visible(false)) 
    ) 
    .ValueAxis(axis => axis 
     .Numeric() 
     .Line(line => line.Visible(false)) 
     .MajorGridLines(lines => lines.Visible(false)) 
    ) 
    .Tooltip(tooltip => tooltip 
     .Visible(true) 
     .Template("#= series.name #: #= value #") 
    ) 
) 

在系列違約,標籤設置爲可見。我無法弄清楚在那裏放置什麼條件。我試過蘭巴表達式,並沒有奏效。我認爲必須有一種方法來獲得系列值,但我無法弄清楚。

這裏是問題

.SeriesDefaults(seriesDefaults => 
    seriesDefaults.Column().Stack(true) 
    .Labels(labels => labels.Background("transparent").Visible(true).Font("40px sans-serif").Position(ChartBarLabelsPosition.Center).Color("black")) 
) 

回答

0

夾頭我不知道,如果你能做到這一點,你所想的方式,如果你能,你就需要在標籤上使用模板與條件語句:

.Labels(labels => labels.Template("#: dataItem.Value #")... 

可能會更容易只是一個字段添加到您的視圖模型只是用於顯示標籤和填充它與一個空字符串,如果該值爲零。