Legend does not display for Column chart

2 posts, 0 answers
  1. Ande2013
    Ande2013 avatar
    17 posts
    Member since:
    Jun 2013

    Posted 01 Jul 2013 Link to this post

    Hi, 

    I have a column chart which does not show the legend even though I have set legend.Visible to true. If I uncomment the .Group line commented in the code below, then the legend starts showing, but unfortunately it displays the default colors rather than those I have customised with m => m.UiColor
                            
    @(Html.Kendo().Chart<WorkItemStatusSummary>()
                          .Name("Chart")
                          .Legend(legend => legend
                              .Visible(true)
                              .Position(ChartLegendPosition.Bottom))
                          .DataSource(ds => ds
                            .Read(read => read
                                .Action("DummyAction", "DummyController")
                                .Data("ChartAdditionalFilterData"))
                            //.Group(g => g.Add(m => m.Status))
                          )
                          .Series(series => series.Column(m => m.Count, m => m.UiColor).Name(""))
                          .CategoryAxis(axis => axis
                                                    .Categories(m => m.Status)
                          )
       )
  2. Iliana Nikolova
    Admin
    Iliana Nikolova avatar
    2593 posts

    Posted 02 Jul 2013 Link to this post

    Hello Andreas,

    Thank you for provided your Chart's configuration. Up to your scenarios:

    • Grouped Chart - by design the colorField is intended to set color to a single point in the series (like in this online demo), not to the entire series. Please note the legend's color matches the series color. Hence in order to achieve the expected result you should set colors to the series through the series.color (like here) or the seriesColors (like in this online demo). Another option is to set the color manually via the options
      @(Html.Kendo().Chart(Model)
        //....
        .Name("chart")
        .Events(ev=>ev.DataBound("onDb"))
      )
              
      <script>    
      function onDb(){
        var chart = $("#chart").data("kendoChart");
        chart.options.series[0].color = chart.options.series[0].data[0].UiColor;
        //....
      }
      </script>

    • Non-grouped chart - by design the Chart's legend shows the series' names. In the provided code snippet the series.name is (""). Hence in order to display the legend you should specify the series' name (for example .Name(" ") ).
    Regards,
    Iliana Nikolova
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top