I am trying to put a sparkline bullet chart in one column of my grid, and I can't figure out how to pass in the data that is currently in my grid. Do you have an example of using a sparkline in a grid in this manner?
Here is what I currently have. However, 1) I had to hardcode the data as an example, since I have not yet figured out how to pass in the data, and 2) it doesn't work, as it's complaining there is a runtime error of an Invalid template
This was my attempt to pass in the data, which failed:
Thanks for your help!
Here is what I currently have. However, 1) I had to hardcode the data as an example, since I have not yet figured out how to pass in the data, and 2) it doesn't work, as it's complaining there is a runtime error of an Invalid template
@(Html.Kendo().Grid<
LabResult
>(Model.LabResults)
.Name("grLabResult")
.Pageable()
.Sortable(sorting => sorting.SortMode(GridSortMode.SingleColumn))
.Columns(columns => {
columns.Bound(a => a.Name);
columns.Bound(a => a.Value).ClientTemplate("#= Value # #= Unit #");
columns.Bound(a => a.Range);
columns.Bound(a => a.Unit).Visible(false);
columns.Bound(a => a.MaxValue).ClientTemplate(
Html.Kendo().Sparkline()
.Name("varSpark_#=LabResultId#")
.Type(SparklineType.Bullet)
.Series( series => series.Bullet(new double[]{70}))
.ValueAxis(axis => axis
.Numeric()
.Min(25)
.Max(75)
.PlotBands(bands =>
{
bands.Add().From(0).To(25).Color("#2890cc").Opacity(0.6);
bands.Add().From(25).To(75).Color("#2890cc").Opacity(0.8);
bands.Add().From(75).To(100).Color("#2890cc").Opacity(0.6);
})
)
.ToClientTemplate()
.ToHtmlString()
);
})
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(a => a.LabResultId);
})
.Events(events => events.Error("error_handler"))
.Sort(sorting => sorting.Add("Name"))
)
)
.Series( series => series.Bullet(new double[]{Double.Parse("#=Value#")}))
.ValueAxis(axis => axis
.Numeric()
.Min(Double.Parse("#=MinValue#"))
.Max(Double.Parse("#=MaxValue#"))
.PlotBands(bands =>
{
bands.Add().From(0).To(Double.Parse("#=MinValue#")).Color("#2890cc").Opacity(0.6);
bands.Add().From(Double.Parse("#=MinValue#")).To(Double.Parse("#=MaxValue#")).Color("#2890cc").Opacity(0.8);
bands.Add().From(Double.Parse("#=MaxValue#")).To(100).Color("#2890cc").Opacity(0.6);
})
)