0

I use Kendo 2015.1.429, MVC 4. I like change dinamically the text leyends in Kendo Chart column:

In my serie I have a text hat can change any time (2016 , 2017, etc):

First I have:

@(Html.Kendo().Chart<TestVM>()
 .Name("ChartTest")
 .Title("Montos")
 .Legend(legend => legend.Position(ChartLegendPosition.Top))
...
.Series(series =>
{
series.Column(model => model.Monto1).Name("Monto 2015").Color("#6BD5C3");
series.Column(model => model.Monto2).Name("Monto 2014").Color("#7992BF");
})

But I like to make dinamically, It throw me an error when I use viewBag:

myView.cshtml
@{
    var leyendaMonto1 = ViewBag.Monto1;
    var leyendaMonto2 = ViewBag.Monto2;
}

series.Column(model => model.MontoAnio1).Name(@leyendaMonto1).Color("#6BD5C3");
model.MontoAnio1).Name(@leyendaMonto2).Color("#6BD5C3");

The error show:

Se produjo una excepción de tipo 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' en System.Core.dll pero no se controló en el código del usuario

Información adicional: La mejor coincidencia de método sobrecargado para 'Kendo.Mvc.UI.Fluent.ChartSeriesBuilderBase<Kendo.Mvc.UI.IChartBarSeries,Kendo.Mvc.UI.Fluent.ChartBarSeriesBuilder<TestVM>>.Name(string)' tiene algunos argumentos no válidos

Any help?

Hernaldo Gonzalez
  • 1,977
  • 1
  • 21
  • 32

2 Answers2

0

instead of

series.Column(model => model.MontoAnio1).Name(@leyendaMonto1)

try

series.Column(model => model.MontoAnio1).Name("@leyendaMonto1")
Mox Shah
  • 2,967
  • 2
  • 26
  • 42
0

I fixed, I change putting a unique text:

series.Column(model => model.Field).Name("myleyend1").Color("#6BD5C3");

Also, I use a Render Event

.Events(events => events.LegendItemClick("test").Render("onRender")) 

then, in the script I replace the text:

function onRender(e) {
        $("#ChartTests g text:contains('leyendaMonto1')").text(myNewValue);
    }
Hernaldo Gonzalez
  • 1,977
  • 1
  • 21
  • 32