5 Answers, 1 is accepted
Do all objects for a group have the same color? If yes, then you could group the data and use the series Color method to set the color for the series based on the value in an object from the group. I attached a small sample project that shows this approach.
Regards,Daniel
Telerik
Yes, all objects of a group have the same color.
I'm getting the data for the chart by calling the action using the DataSource option. So the code for my chart looks something like the following:
@(Html.Kendo().Chart<ViewModel>()
.Name(
"chart"
)
.DataSource(ds => ds
.Read(read => read.Action(
"GetProducts"
,
"Products"
)
.Group(group => group.Add(model => model.Country))
.
.
.
)
Thanks,
Ronald
There isn't a way to use the dataSource to pass the data and specify the color for each group. You should either bind the data on the server as demonstrated in the attached project or load the data via Ajax and then set the series to the chart options.
Regards,Daniel
Telerik
var
dataSource =
new
kendo.data.DataSource({
//Your transport object here
group: {
field:
'Manager'
//Whatever group you need
},
schema: {
data:
'Data'
,
model: {
fields: {
Date: {
type:
"date"
}
}
}
}
});
var
chart = $(
"#chart"
).kendoChart({
dataSource: dataSource,
legend: {
position:
"bottom"
},
series:[
{
type:
'line'
,
field:
'Amount'
,
categoryField:
'Date'
,
colorField:
'Color'
,
groupColor:
function
(item)
{
var
series = item.series;
series.color = series.data[item.index].Color;
}
}]);
{
"Data"
:[{
"Date"
:
"2013-08-01T00:00:00"
,
"Amount"
:100,
"Manager"
:
"Greivin Britton"
,
"Color"
:
"#D13487"
}, {... more records here..}]}
--
Greivin
A truly life saver! :D I had this very same problem and I was getting mad not being able to solve it. Your solution worked great and it is very interesting because:
1 - colorField is not officially suported for line charts but it works with your solution though
2 -groupColor is not in the official docs :O
Thanks again!