I have an Angular app that draws multiple charts. I am trying to set the chart options in code using the k-options directive. Below are my options for the stackedBarCode.
vm.stackedBarChartOptions = {
//dataSource: new kendo.data.DataSource({
// transport: {
// type: 'json',
// read: function (options) {
// var request = new ShipmentManagementRequest(11736);
// request.Carriers = vm.shipmentManagementRequest.Carriers;
// request.RequestType = "CarMix";
// shipmentService.getMixChartData(request)
// .then(function(result) {
// options.success(result.data);
// console.log("Original Read Called");
// }).catch(function(error) {
// options.error(error);
// });
// }
//},
//group: [
// { field: "category" }
//],
//sort: {
// field: "date",
// dir: "asc"
//},
//schema: {
// model: {
// fields: {
// date: {
// type: "date"
// }
// }
// }
//}
//}),
theme:
'Office365'
,
seriesDefaults: {
stack: {
type:
"100%"
}
},
series: [
{
field:
'percent'
,
name:
'#= group.value #'
,
}
],
categoryAxis: {
field:
"date"
,
labels: {
format:
"MMM-yy"
}
},
legend: {
position:
"bottom"
,
visible:
false
},
valueAxis: {
line: {
visible:
false
},
labels: {
rotation:
"auto"
}
},
tooltip: {
visible:
true
,
template:
"#= series.name #: #= kendo.format('{0:p2}',value) #"
},
render:
function
(e) {
vm.setChartOptions(e);
}
}
Since each chart has a different set of data being used for the graph I cannot set a single datasource in the options. I am trying to set the datasource in the code as shown below.
var
chartDataEl = $(
'#'
+ myChart.chartData.htmlID).data(
'kendoChart'
);
if
(myChart.chartData.chartOptions ===
'stackedBarChartOptions'
) {
chartDataEl.dataSource =
new
kendo.data.DataSource({
transport: {
type:
'json'
,
read:
function
(options) {
var
request =
new
ShipmentManagementRequest(11736);
request.Carriers = vm.shipmentManagementRequest.Carriers;
request.RequestType = options.data.htmlId;
shipmentService.getMixChartData(request)
.then(
function
(result) {
options.success(result.data);
var
chart = options.data.chart;
chart.refresh();
chart.redraw();
}).
catch
(
function
(error) {
options.error(error);
});
}
},
group: [
{ field:
"category"
}
],
sort: {
field:
"date"
,
dir:
"asc"
},
schema: {
model: {
fields: {
date: {
type:
"date"
}
}
}
}
});
}
else
{
/* set data source for other chart types */
}
This works for other chart types (i.e. pie, standard bar, line), but when I perform the refresh for the stacked bar the horizontal axis loads the date information from the response but no bars are drawn. See attached. What is happening that is preventing the data from displaying since it works on the other chart types.