Using kendo stock chart (2015.2.805) with AngularJS (1.3.16) like this
Directive template:
<
div
kendo-stock-chart
=
"graphCtrl.chartobject"
k-options
=
"graphCtrl.chartConfiguration"
id
=
"kendo-chart"
></
div
>
Directive controller:
function graphDirectiveController($scope, $timeout, dataService) {
var that = this;
getConfiguration();
that.chartConfiguration = {
theme: "customTheme",
dataSource: new kendo.data.DataSource({
transport: {
read: function (options) {
bondCompareDataService.getGraphData(that.graphId, that.bondIds).then(function (result) {
options.success(result.data);
});
}
},
schema: {
model: {
fields: {
date: { type: "date" }
}
}
}
}),
autoBind: false,
title: {
text: ""
},
legend: {
position: "bottom",
visible: true
},
chartArea: {
margin: {
right: 40,
top: 20,
bottom: 20,
left: 10
}
},
dateField: "date",
categoryAxis: {
labels: {
font: "12px Roboto, Helvetica, Arial"
},
title: {
color: "#dddddd"
}
},
series: [],
navigator: {
series: {
field: "navigatorseries",
type: "line",
missingValues: "interpolate"
},
categoryAxis: {
labels: {
font: "12px Roboto, Helvetica, Arial"
}
}
}
}
function getConfiguration () {
dataService.getGraphConfigurations(that.graphid).then(function (result) {
var configurations = result.data;
var chartOptions = that.chartobject.options;
angular.forEach(configurations, function (config) {
chartOptions.series.push({
categoryField: "date",
name: config.name,
field: config.seriesKey,
type: "line",
markers: {
size: 2
},
tooltip: {
visible: true,
template: getTooltipTemplate(config.formatAs)
}
});
});
refreshData();
that.chartobject.redraw();
});
}
function refreshData () {
that.chartobject.dataSource.read();
that.chartobject.refresh();
}
function getTooltipTemplate (formatAs) {
if (formatAs === "Rate") {
return "<
strong
>#: series.name # </
strong
><
br
/> #: kendo.toString(category, 'd' )#: #: kendo.toString(value, 'n2') #%";
} else {
return "<
strong
>#: series.name # </
strong
><
br
/> #: kendo.toString(category, 'd' )#: #: kendo.toString(value, 'n2') #";
}
}
}
Thanks,
Casper