I have a bar chart that is getting its data from my controller in the form of Json data as shown below:
[
{"SiteId":1,"Hour":9,"Quantity":9.0000,"Value":43.0500,"NumCustomers":5},
{"SiteId":1,"Hour":10,"Quantity":18.0000,"Value":43.6900,"NumCustomers":8},
{"SiteId":1,"Hour":11,"Quantity":7.0000,"Value":22.4200,"NumCustomers":3},
{"SiteId":1,"Hour":14,"Quantity":1.0000,"Value":1.0000,"NumCustomers":1}
{"SiteId":2,"Hour":9,"Quantity":10.0000,"Value":48.0500,"NumCustomers":7},
{"SiteId":2,"Hour":10,"Quantity":20.0000,"Value":83.6900,"NumCustomers":11},
{"SiteId":2,"Hour":11,"Quantity":9.0000,"Value":27.4200,"NumCustomers":5},
{"SiteId":2,"Hour":14,"Quantity":3.0000,"Value":11.0000,"NumCustomers":4}
{"SiteId":3,"Hour":9,"Quantity":7.0000,"Value":33.0500,"NumCustomers":4},
{"SiteId":3,"Hour":10,"Quantity":16.0000,"Value":35.6900,"NumCustomers":7},
{"SiteId":3,"Hour":11,"Quantity":7.0000,"Value":22.4200,"NumCustomers":3},
{"SiteId":3,"Hour":14,"Quantity":2.0000,"Value":5.0000,"NumCustomers":2}
]
As you can see, there are multiple sites for the same hours. The horizontal axis should represent each hour from the data. Each hour should have a column representing each site, very similar to the 'Column Chart' example on your site. The code example on the site shows the series data like this:
.Series(series => {
series.Column(new double[] { 3.907, 7.943, 7.848, 9.284, 9.263, 9.801, 3.890, 8.238, 9.552, 6.855 }).Name("India");
series.Column(new double[] { 4.743, 7.295, 7.175, 6.376, 8.153, 8.535, 5.247, -7.832, 4.3, 4.3 }).Name("Russian Federation");
series.Column(new double[] { 0.010, -0.375, 1.161, 0.684, 3.7, 3.269, 1.083, -5.127, 3.690, 2.995 }).Name("Germany");
series.Column(new double[] { 1.988, 2.733, 3.994, 3.464, 4.001, 3.939, 1.333, -2.245, 4.339, 2.727 }).Name("World");
})
My current code that shows the hourly totals for 1 site is listed below, but I'd like this to work for multiple sites as shown the in above collection of Json data. What is the best way to accomplish this?
My current code:
@(Html.Kendo().Chart<
CBECloudBO2.ViewModels.ChartHourlySales
>()
.Name("chartHourlySales")
.Title("Hourly Sales")
.DataSource(datasource => datasource
.Read(read => read.Action("Chart_HourlySales", "Home")))
.Legend(legend => legend
.Visible(false))
.ChartArea(chartArea => chartArea
.Background("transparent"))
.Series(series =>
{
series.Column(p => p.Value).Name("Total Sales");
})
.CategoryAxis(axis => axis
.Name("series-axis")
.Line(line => line.Visible(false))
)
.CategoryAxis(axis => axis
.Name("label-axis")
.Categories(p => p.Hour)
)
.ValueAxis(axis => axis
.Numeric()
.AxisCrossingValue(0, int.MinValue)
)
.Tooltip(tooltip => tooltip
.Visible(true)
.Format("{0}%")
.Template("#= series.name #: #= value #")
)
)
Thanks,
Shawn