如何隐藏传说中的所有年份,除了剑道图Mvc中的最后一年

how to hide all years in legend except the last one in kendo chart Mvc

本文关键字:Mvc 一年 最后 隐藏 何隐藏 传说中      更新时间:2023-09-26

我真的不知道如何隐藏除了去年(2014)之外的所有传奇年份。我需要当页面打开时,只显示2014年,而不是所有年份。

当用户在此页面上重定向时,他应该只看到2014(默认情况下)。我不知道如何隐藏其他价值观。如果他想查看其他年份的值,他只需点击其他图例值,然后绘制所选年份的可视化值

这是我在Razor引擎Mvc应用程序中的代码:

  @(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;
                };
            }

如果在模型中读取单个系列,然后将年份指定为系列名称,则会在图例中看到单个年份。

从上面的代码中,我假设你每年都会作为一个单独的系列阅读,这就是为什么你会在传说中看到它们。

我如何按图表类型创建系列的示例:

 .Series(series =>
                            {
                                foreach (var s in Model.KendoChartSery)
                                {
                                    var templateString = "${value}";
                                    switch (s.ChartType)
                                    {
                                        case 1:
                                            series.Line(s.Values).Name(s.ChartSeriesId).Color(s.Color).Tooltip(tooltip => tooltip.Visible(true).Template(templateString));
                                            break;
                                        case 2:
                                            series.Column(s.Values).Name(s.ChartSeriesId).Color(s.Color).Tooltip(tooltip => tooltip.Visible(true).Template(templateString));
                                            break;
                                        case 3:
                                            series.Bar(s.Values).Name(s.ChartSeriesId).Color(s.Color).Tooltip(tooltip => tooltip.Visible(true).Template(templateString));
                                            break;
                                    }
                                }
                            })