Get datasource iterration object

3 posts, 1 answers
  1. Antoine
    Antoine avatar
    2 posts
    Member since:
    Mar 2016

    Posted 11 Mar Link to this post

    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. Answer
    Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 15 Mar Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Antoine
    Antoine avatar
    2 posts
    Member since:
    Mar 2016

    Posted 15 Mar in reply to Daniel Link to this post

    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

     

Back to Top