c# - shield ui chart: generate series dynamically? -
is there way add series chart without knowing ahead of time how many series in it? example want graph on x axis month on variable selection of years. each year series.
i thought binding ienumerable while grouping year--and creating series on each group item, couldn't envision code.
i got work custom helper (htmlhelper extension method). adapted example http://demos.shieldui.com/aspnet/aspnet-chart/programmatic-chart-creation, example asp.net web forms. i'm doing mvc. solution involved using chartbuilder<> object within helper.
public static class chartextensions { public static chartbuilder<propertypivotaverageamountpermonth_result> annualcomparison(this htmlhelper html, int id) { mydatabaseentities db = new mydatabaseentities(); var results = db.propertypivotaverageamountpermonth(id); chartbuilder<propertypivotaverageamountpermonth_result> chart = new chartbuilder<propertypivotaverageamountpermonth_result>(html, results); chart.axisx(axisx => axisx.categoricalvalues("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec")); chart.primaryheader(header => header.text("annual cost comparisons")); foreach (var year in results) { chart.dataseries(s => s.line() .collectionalias(year.year.tostring()) .data(new object[] { new { x=0, y=year.c1 }, new { x=1, y=year.c2 }, new { x=2, y=year.c3 }, new { x=3, y=year.c4 }, new { x=4, y=year.c5 }, new { x=5, y=year.c6 }, new { x=6, y=year.c7 }, new { x=7, y=year.c8 }, new { x=8, y=year.c9 }, new { x=9, y=year.c10 }, new { x=10, y=year.c11 }, new { x=11, y=year.c12 } })); } return chart; }
Comments
Post a Comment