AngularJS scope HELP WANTED
HTML
<script src="https://rawgit.com/gevgeny/ui-highcharts/master/samples/jsfiddle-scripts.js"></script>
<!--This scripts are necessary only for local running, jsfiddle version uses resources. -->
<script src="../../bower_components/jquery/dist/jquery.js"></script>
<script src="../../bower_components/angular/angular.js"></script>
<script src="../../bower_components/highstock-release/highstock.src.js"></script>
<script src="../../dist/ui-highcharts.js"></script>
<script src="demo.js"></script>
<div ng-app="myApp" ng-controller="MainCtrl">
<!-- adding ng-if postpone ui-charts init-->
<ui-chart ng-if="data" series="data" options="options" title="Example company stock">
<y-axis title="foo">
<labels>
<span>{{ value }} dunno what this is for</span>
</labels>
</y-axis>
<y-axis opposite title="Value">
<labels>
<span>${{ value }}</span>
</labels>
</y-axis>
<tooltip use-html>
<span ng-show="series.name == 'Value'">{{ x }}: ${{ y }}</span>
</tooltip>
</ui-chart>
<p>{{ iWishThisCouldBeGlobal }}</p>
</div>
JavaScript
angular.module('myApp', ['ui-highcharts']).controller('MainCtrl', function ($http, $scope) {
$scope.loadData = function(){
return $http.jsonp('http://dev.markitondemand.com/Api/v2/InteractiveChart/jsonp?jsoncallback=JSON_CALLBACK¶meters=%7B%22Normalized%22%3Afalse%2C%22NumberOfDays%22%3A30%2C%22DataPeriod%22%3A%22Day%22%2C%22Elements%22%3A%5B%7B%22Symbol%22%3A%22AAPL%22%2C%22Type%22%3A%22price%22%2C%22Params%22%3A%5B%22c%22%5D%7D%5D%7D')
.then(function(res){
return res.data;
});
};
$scope.promise = $scope.loadData(); // This is not data! This is promise which can be used to fetch data when it is loaded
$scope.options = {
chart: {
spacing: 40,
height: 360
},
legend : {
enabled : false
},
xAxis : [{
categories : ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
}]
};
$scope.promise.then(function(data) {
// Data is loaded. Now we can init ui-hichcharts
$scope.data = [{
name : 'Value',
type : 'line',
data : data.Positions,
yAxis : 1
}];
console.log($scope.data, $scope.options);
});
});