I'm trying to show a line chart (date axis) that changes color. I realize the best way to do this is probably to have multiple series and each series a different color.
@model TimeLineChartViewModel
<
div
style
=
""
>
@(Html.Kendo().Chart(Model.Data)
.Name("chart123jjhj423")
.Title("Probability of Failure")
.Legend(false)
.Series(series =>
{
foreach (var dataGroup in Model.Data.GroupBy(x => x.Color))
{
series.Line(x => x.Value, x => x.DateTime)
.NoteTextField(Util.GetPropertyName<
TimeLineChartDataPoint
>(x => x.Note))
//.CategoryField("Color") // causes error (Cannot read property 'getTime' of undefined)
.Notes(notes => notes
.Label(label => label
.Position(ChartNoteLabelPosition.Outside))
.Position(ChartNotePosition.Bottom))
.Color(dataGroup.Key)
.Style(ChartLineStyle.Smooth)
.Markers(x => x.Visible(false));
}
})
.CategoryAxis(axis => axis
.Date()
.BaseUnit(ChartAxisBaseUnit.Days)
.RoundToBaseUnit(false)
// .Title("time")
.Labels(labels => labels.Rotation(310).Step(365 * 5).Format("yyyy"))
.MajorGridLines(lines => lines.Visible(false))
.MinorGridLines(lines => lines.Visible(false))
.MajorTicks(lines => lines.Visible(true).Step(365 * 5).Size(15))
.MinorTicks(lines => lines.Visible(false).Step(365))
)
.ValueAxis(axis => axis.Numeric()
.Max(1.05)
.Labels(labels =>
labels.Template("#= kendo.format('{0:P0}', value ) #")
// labels.Visible(true)
)
.Title("Probability of Asset Failure")
.MajorGridLines(lines => lines.Visible(false))
//.MajorUnit(0.2)
//.MinorUnit(0.5)
.Visible(true)
)
//.Zoomable(zoomable => zoomable
// .Mousewheel(mousewheel => mousewheel.Lock(ChartAxisLock.Y))
// .Selection(selection => selection.Lock(ChartAxisLock.Y))
//)
.Tooltip(tooltip => tooltip
.Visible(true)
.Template("#= kendo.format('{0:p0}', value) # - #= kendo.toString(category, 'd') #")
//.Template("#= kendo.toString(category, 'd') # ")
))
</
div
>
public class TimeLineChartViewModel
{
public List<
TimeLineChartDataPoint
> Data { get; set; }
public bool Legend { get; set; }
public string Title { get; set; }
public string XAxisTitle { get; set; }
public string YAxisTitle { get; set; }
}
public class TimeLineChartDataPoint
{
public DateTime DateTime { get; set; }
public double Value { get; set; }
public string Note { get; set; }
public string Color { get; set; }
}
When I try running the above, only one color shows for all data points? How do I get the line color to be different? Setting the Category field in the series generates an error:
jquery?v=iMGCS2tVV4GjIWlaD6Jt8YXksWeHsA8tUmaXpQPvHJw1:1 Uncaught TypeError: Cannot read property 'getTime' of undefined
at fu (kendo?v=Ch_M82a2Ve1skh_-TT5n-noxLIMFwTpBlRrbN6I9v7c1:1)
at wo (kendo?v=Ch_M82a2Ve1skh_-TT5n-noxLIMFwTpBlRrbN6I9v7c1:1)
at hi (kendo?v=Ch_M82a2Ve1skh_-TT5n-noxLIMFwTpBlRrbN6I9v7c1:1)
at init.roundToTotalStep (kendo?v=Ch_M82a2Ve1skh_-TT5n-noxLIMFwTpBlRrbN6I9v7c1:1)
at new init (kendo?v=Ch_M82a2Ve1skh_-TT5n-noxLIMFwTpBlRrbN6I9v7c1:1)
at initFields (kendo?v=Ch_M82a2Ve1skh_-TT5n-noxLIMFwTpBlRrbN6I9v7c1:1)
at init (kendo?v=Ch_M82a2Ve1skh_-TT5n-noxLIMFwTpBlRrbN6I9v7c1:1)
at i [as constructor] (kendo?v=Ch_M82a2Ve1skh_-TT5n-noxLIMFwTpBlRrbN6I9v7c1:1)
at new i (kendo?v=Ch_M82a2Ve1skh_-TT5n-noxLIMFwTpBlRrbN6I9v7c1:1)
at i.createCategoryAxes (kendo?v=Ch_M82a2Ve1skh_-TT5n-noxLIMFwTpBlRrbN6I9v7c1:1)
Attached I have attached some sample data (sorry it's a screenshot).