I know this has been asked before and referenced in regard to jquery (https://www.telerik.com/forums/different-color-for-each-bar-in-bar-chart-for-a-single-series-) as well as others but I can't seem to figure out how to do it in Core. I have a simple Column chart from bound sql datasource. Is it possible to set the category columns to different colors? Note that the number of categories is variable.
Here is my controller action:
public ActionResult AttributeSummary_Read(int? id)
{
{
var assessmentId = new SqlParameter("@assessmentId", id);
var data = _context.Reports.FromSql("rpt_AttributeSummaryBySite @assessmentId", assessmentId).AsNoTracking().ToList();
List<
Report_AttributeSummaryVM
> AttributeSummaryList = data.Select(x => new Report_AttributeSummaryVM
{
AttributeName = x.AttributeName,
SumAssessmentValue = x.SumAssessmentValue,
AssessmentYear = x.AssessmentYear
}).ToList();
return Json(AttributeSummaryList);
}
As an example with 3 categories, my stored proc produces this data:
OutcomeName | AssessmentYear | AvgOutcomeValue
Best Practices in Ministry 2019 5.16
Leadership Development 2019 6
Strategic Alignment of Ministries 2019 4.59
Here is the Razor View
<
div
class
=
"container w-75"
>
<
div
class
=
"demo-section k-content wide"
>
@(Html.Kendo().Chart<
ICPCore.Models.Reports
>()
.Name("chartOutcomeSummary")
.Title("Outcomes Summary by Site")
.Legend(legend => legend
.Position(ChartLegendPosition.Top)
)
.DataSource(ds => ds.Read(read => read.Action("OutcomeAreaSummary_Read", "Reports").Data("curId")))
.Series(series =>
{
series.Column(model => model.AvgOutcomeValue).Name("AvgOutcomeValue").CategoryField("OutcomeName");
})
.CategoryAxis(axis => axis
.Categories(model=>model.OutcomeName)
.Labels(labels => labels.Rotation(0))
.MajorGridLines(lines => lines.Visible(false))
)
.ValueAxis(axis => axis.Numeric()
.Labels(labels => labels.Format("{0:N0}"))
.MajorUnit(1)
.Max(10)
.Min(1)
.Line(line => line.Visible(false))
)
.Tooltip(tooltip => tooltip
.Visible(true)
.Format("{0:N0}")
)
.AutoBind(true)
)
</
div
>
</
div
>