Your search did not match any results.

Charts - Dynamic Series from the DataSource

In certain scenarios, you may need to add more series to the data source after you created the Chart.

In this case, arrange your data source structure as follows:

[
    {seriesName: series1, arg: arg11Value, val: value11 }
    {seriesName: series1, arg: arg12Value, val: value12 }
    ...
    {seriesName: seriesM, arg: argM1Value, val: valueM1 }
    {seriesName: seriesM, arg: argM2Value, val: valueM2 }
    ...
]

Every object in the data source should correspond to a point in a single series.

Backend API
@(Html.DevExtreme().Chart() .ID("chart") .Palette(VizPalette.Violet) .CommonSeriesSettings(s => s .ArgumentField("Country") .ValueField("Oil") .Type(SeriesType.Bar) ) .SeriesTemplate(t => t .NameField("Year") .CustomizeSeries(@<text> function(valueFromNameField) { return valueFromNameField === 2009 ? { type: "line", label: { visible: true }, color: "#ff3f7a" } : {}; } </text>) ) .Title(t => t .Text("Oil Production") .Subtitle(s => s.Text("(in millions tonnes)")) ) .Export(e => e.Enabled(true)) .Legend(l => l .VerticalAlignment(VerticalEdge.Bottom) .HorizontalAlignment(HorizontalAlignment.Center) ) .DataSource(Model) )
using DevExtreme.AspNet.Data; using DevExtreme.AspNet.Mvc; using DevExtreme.MVC.Demos.Models.SampleData; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; namespace DevExtreme.MVC.Demos.Controllers { public class ChartsController : Controller { public ActionResult SeriesTemplates() { return View(SampleData.OilProductionData); } } }
using System; using System.Collections.Generic; using System.Linq; namespace DevExtreme.MVC.Demos.Models { public class OilProduction { public int Year { get; set; } public string Country { get; set; } public double Oil { get; set; } } }
using System.Collections.Generic; namespace DevExtreme.MVC.Demos.Models.SampleData { public partial class SampleData { public static readonly IEnumerable<OilProduction> OilProductionData = new[] { new OilProduction { Year = 1970, Country = "Saudi Arabia", Oil = 186.7 }, new OilProduction { Year = 1970, Country = "USA", Oil = 557.8 }, new OilProduction { Year = 1970, Country = "Iran", Oil = 207.3 }, new OilProduction { Year = 1970, Country = "Mexico", Oil = 24.7 }, new OilProduction { Year = 1980, Country = "Saudi Arabia", Oil = 480.4 }, new OilProduction { Year = 1980, Country = "USA", Oil = 423.2 }, new OilProduction { Year = 1980, Country = "Iran", Oil = 74.3 }, new OilProduction { Year = 1980, Country = "Mexico", Oil = 109.2 }, new OilProduction { Year = 1990, Country = "Saudi Arabia", Oil = 319.6 }, new OilProduction { Year = 1990, Country = "USA", Oil = 340.1 }, new OilProduction { Year = 1990, Country = "Iran", Oil = 183.3 }, new OilProduction { Year = 1990, Country = "Mexico", Oil = 145.3 }, new OilProduction { Year = 1990, Country = "Russia", Oil = 499.6 }, new OilProduction { Year = 2000, Country = "Saudi Arabia", Oil = 465 }, new OilProduction { Year = 2000, Country = "USA", Oil = 282.9 }, new OilProduction { Year = 2000, Country = "Iran", Oil = 195.5 }, new OilProduction { Year = 2000, Country = "Mexico", Oil = 148.3 }, new OilProduction { Year = 2000, Country = "Russia", Oil = 375.3 }, new OilProduction { Year = 2008, Country = "Saudi Arabia", Oil = 549.7 }, new OilProduction { Year = 2008, Country = "USA", Oil = 280 }, new OilProduction { Year = 2008, Country = "Iran", Oil = 214.9 }, new OilProduction { Year = 2008, Country = "Mexico", Oil = 132.1 }, new OilProduction { Year = 2008, Country = "Russia", Oil = 503.2 }, new OilProduction { Year = 2009, Country = "Saudi Arabia", Oil = 428.4 }, new OilProduction { Year = 2009, Country = "USA", Oil = 298.9 }, new OilProduction { Year = 2009, Country = "Iran", Oil = 217.2 }, new OilProduction { Year = 2009, Country = "Mexico", Oil = 121.6 }, new OilProduction { Year = 2009, Country = "Russia", Oil = 493.1 } }; } }
#chart { height: 440px; width: 100%; }

This demo uses the structure displayed above to organize data:

{
    year: 1970,
    country: 'Saudi Arabia',
    oil: 192.2,
}

To define series, use the commonSeriesSettings object to specify common settings for all series: the argumentField, the valueField, and the type.

Then, use the seriesTemplate configuration object to define a template for the series. Within this object, assign the data source field that specifies the series name to the nameField property.

If you need to specify individual values for properties of a particular series, assign a callback function to the customizeSeries property of the seriesTemplate object. This demo uses the customizeSeries function to display a line instead of a bar for year: 2009.