I really don't know how to hide all legend years except last (2014). I need when the page opens , to show only 2014 year, not all years.

When user redirected on this page, he should see only 2014 ( by default) . I don't know how to hide other values. If he wants to see values for other years - he just click on other legend values and then chart visualized values for selected year(s)

This is my code in Razor engine Mvc App :

  @(Html.Kendo().Chart()
                              .HtmlAttributes(new { style = "height: 650px;" })
                              .Name("chart")
                              .Legend(leg => leg.Position(ChartLegendPosition.Top))
                              .Legend(leg => leg.Position(ChartLegendPosition.Top))
                              .ChartArea(area => area.Background("transparent"))
                              .SeriesDefaults(l => l.Column().Visible(false))
                              .Series(series =>
                              {
                                  foreach (var def in Model.Series)
                                  {
                                      string curVal = Convert.ToString(DateTime.Now.Year - 1);


                                      if (def.Years != curVal)
                                      {


                                           series.Column(def.Value).Name(def.Years).Field("Years").Visible(true);
                                      }

                                      else
                                      {
                                          series.Column(def.Value).Name(def.Years).Visible(true);
                                      }
                                  }
                              })
                              .CategoryAxis(axis => axis.Categories(Model.Categories).Labels(label => label.Rotation(-90)))
                              .ValueAxis(axis => axis.Numeric().Labels(labels => labels.Format("{0:P}")))
                              .SeriesColors("red", "blue", "yellow", "#006634", "#c72e15")

                              .Tooltip(tooltip => tooltip.Visible(true).Template("#= category # <br/>  #= series.name # <br/>   (#= kendo.format('{0:P}',value )#) "))
                              .SeriesColors("#FC8701", "#1500D7", "#00D72F", "#D7AC00", "#FC1F01", "#8F0774", "#05D5FA", "#FCF001", "#01FC1F", "#84491B")
                              .Events(ev => ev.AxisLabelClick("onAxisLabelClick")
                                             .LegendItemClick("dataYearLoad")
                                    )
                             )
                    </div>
                </div>
            </fieldset>

        </div>


        <script type="text/javascript">

            function dataYearLoad() {
                var chart = $("#chart").data("kendoChart");
                chart.options.series["Years"].visible = false;


                for (var i = 0, length = series.length; i < length; i++) {
                    series[i].stack = stack;
                 //   series[i].visible = (types.indexOf(series[i].type) !== -1);
                    series[i].visibleInLegend = false;
                };

            }

Related posts

Recent Viewed