kojirosan
kojirosan

Reputation: 507

How to Disable Custom Legend Kendo Chart

Using Kendo MVC Kendo Chart. I want to disable legend of the chart. It looks like that:

:enter image description here

I don't want to show left side of my chart so how can i disappear this legend? I tried to make true's to false but i am failed many times.

   @(Html.Kendo().Chart(Model)
  .Name("chart")

.Title(title => title

    .Align(ChartTextAlignment.Center)

)

.Series(series =>
{
    series.Bar(
        model => model.Deger,
        model => model.Color
    )
    .Labels(labels => labels.Background("transparent").Visible(true));
})
.CategoryAxis(axis => axis
    .Categories(model => model.Parameter)
    .MajorGridLines(lines => lines.Visible(true))
            .Line(line => line.Visible(true))
)
.ValueAxis(axis => axis.Numeric()

            .MajorGridLines(lines => lines.Visible(true))
    .Visible(true)
)
  .ChartArea(chartArea => chartArea.Background("transparent"))
   .Tooltip(tooltip => tooltip
   .Visible(true)
                .Template("#= category #: #= value #"))
    )

Upvotes: 2

Views: 2839

Answers (1)

Nic
Nic

Reputation: 12846

Just add .Legend(false) to your chart.

@(Html.Kendo().Chart(Model)
    .Name("chart")
    .Title(title => title.Align(ChartTextAlignment.Center))
    .Series(series =>
    {
        series.Bar(
            model => model.Deger,
            model => model.Color
        )
        .Labels(labels => labels.Background("transparent").Visible(true));
    })
    .CategoryAxis(axis => axis
        .Categories(model => model.Parameter)
        .MajorGridLines(lines => lines.Visible(true))
            .Line(line => line.Visible(true))
    )
    .ValueAxis(axis => axis.Numeric()
            .MajorGridLines(lines => lines.Visible(true)).Visible(true)
    )
    .ChartArea(chartArea => chartArea.Background("transparent"))
   .Tooltip(tooltip => tooltip
       .Visible(true)
       .Template("#= category #: #= value #"))
   .Legend(false)   
)

Alternatively, you can control the legend using JavaScript. Useful if you want to hide certain legend items.

var chart = $("#chart").data("kendoChart");
chart.options.series[0].visibleInLegend = false;
chart.redraw();

Upvotes: 1

Related Questions