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

Get datasource iterration object

2 Answers 79 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Antoine
Top achievements
Rank 1
Antoine asked on 11 Mar 2016, 08:26 AM

Hi,

I'm using databinding on a line chart. I want to display multiple serie so i write this code : 

this.ChartBuilder = htmlHelper.Kendo().Chart<SerieValueViewModel>()
     .Name(Guid.NewGuid().ToString())
     .Title(this.Name)
     .DataSource(dataSource =>
      {
          dataSource.Read(read => read
              .Action(this.DataSourceViewModel.View,this.DataSourceViewModel.Action))
              .Group(group => group.Add(m => m.Symbol))
              .Sort(s => s.Add(m => m.Date).Ascending());
      })
      .Series(series =>
      {
          series.Line(v => v.Value, v => v.Date)
                .Name("#= group.value #")
                .Aggregate(this.CategoryAxisViewModel.Aggregation)
                .Stack(false)
                .Markers(m => m.Visible(true).Size(3));
       });
 }

Now, i want to display a color to my serie. But this color depend of my serie and i only have a list of value that i've grouped.

I tried to use a new object named SerieViewModel which contains List of SerieValueViewModel and a color and do something like this...

this.ChartBuilder = htmlHelper.Kendo().Chart<SerieViewModel>()
     .Name(Guid.NewGuid().ToString())
     .Title(this.Name)
     .DataSource(dataSource =>
      {
          dataSource.Read(read => read
              .Action(this.DataSourceViewModel.View,this.DataSourceViewModel.Action));
      })
      .Series(series =>
      {
         // I want to do something like this ...
         // Get my serieViewModel which is iterate
         var mySerie = iterateObject;
       
         foreach(var valueViewModel in mySerie.ValueViewModelCollection)
         {
            series.Line(valueViewModel  => valueViewModel.Value, valueViewModel  => valueViewModel.Date)
                .Name(mySerie.Name)
                .Aggregate(this.CategoryAxisViewModel.Aggregation)
                .Stack(false)
                .Markers(m => m.Visible(true).Size(3))
                .Color(mySerie.Color);
         }
       });
}

This is exactly what i need but i can't get my serieViewModel which is actually iterate, so i can't bind my values and use my color.

I want to use this reflection to put a "serieType" in my serieViewModel object too and construct charts with different series type like a chart with a line and an area.

There is a way to get my object which is iterate or get some of his properties ?

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 15 Mar 2016, 08:17 AM
Hi,

You cannot iterate over the series data on the server if it is bound using a dataSource via Ajax. In this case you can use the chart dataBound event to set the series color or the type e.g.
 
function onDataBound() {
    var series = this.options.series;
    for (var idx = 0; idx < series.length; idx++) {
        series[idx].color = series[idx].data[0].ColorField;
        series[idx].type = series[idx].data[0].TypeField;
    }
}


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Antoine
Top achievements
Rank 1
answered on 15 Mar 2016, 09:45 AM

Thanks Daniel,

I think, i will give up this solution and don't use Ajax...

It's too bad that we can not use expression in all function (like Color() or Markers()) when we use datasource Ajax :/

Regards,

Antoine

 

Tags
Charts
Asked by
Antoine
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Antoine
Top achievements
Rank 1
Share this question
or