This is a migrated thread and some comments may be shown as answers.

Legend does not display for Column chart

1 Answer 247 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Ande2013
Top achievements
Rank 1
Ande2013 asked on 01 Jul 2013, 01:29 PM
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)
                      )
   )

1 Answer, 1 is accepted

Sort by
0
Iliana Dyankova
Telerik team
answered on 02 Jul 2013, 08:12 AM
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!
Tags
Chart
Asked by
Ande2013
Top achievements
Rank 1
Answers by
Iliana Dyankova
Telerik team
Share this question
or