【发布时间】:2016-10-24 18:25:38
【问题描述】:
我正在开发一个 Angular(1.5.8) 项目并使用安装的凉亭highcharts-nggithub link
添加highcharts-ng为:
angular.module('myapp',
['highcharts-ng',
// more modules here..
])
在我的 html 文件中,我使用以下内容:
<div class="row">
<highchart id="chart1" config="chartConfig"></highchart>
</div>
在我的控制器文件中: DashboardController.$inject = ['$scope', 'Principal', 'LoginService', '$state'];
function DashboardController ($scope, Principal, LoginService, $state) {
$scope.chartConfig ={
....// configuration details
};
}();
我把
<script src="bower_components/highcharts-ng/dist/highcharts-ng.js"></script>
转入index.html
不幸的是,我收到了这样的错误:
angular.js:13920 TypeError: Cannot read property 'Chart' of undefined
at initChart (highcharts-ng.js:334)
at linkWithHighcharts (highcharts-ng.js:349)
at highchartsCb (highcharts-ng.js:463)
at processQueue (angular.js:16383)
at angular.js:16399
at Scope.$eval (angular.js:17682)
at Scope.$digest (angular.js:17495)
at Scope.$apply (angular.js:17790)
at done (angular.js:11831)
at completeRequest (angular.js:12033)
谁能解释一下这个问题?
chartConfig 的详细信息,它是 https://github.com/pablojim/highcharts-ng 的副本,我用它来测试 highcharts 是否有效:
function DashboardController ($scope) {
//This is not a highcharts object. It just looks a little like one!
$scope.chartConfig = {
options: {
//This is the Main Highcharts chart config. Any Highchart options are valid here.
//will be overriden by values specified below.
chart: {
type: 'bar'
},
tooltip: {
style: {
padding: 10,
fontWeight: 'bold'
}
}
},
//The below properties are watched separately for changes.
//Series object (optional) - a list of series using normal Highcharts series options.
series: [{
data: [10, 15, 12, 8, 7]
}],
//Title configuration (optional)
title: {
text: 'Hello'
},
//Boolean to control showing loading status on chart (optional)
//Could be a string if you want to show specific loading text.
loading: false,
//Configuration for the xAxis (optional). Currently only one x axis can be dynamically controlled.
//properties currentMin and currentMax provided 2-way binding to the chart's maximum and minimum
xAxis: {
currentMin: 0,
currentMax: 20,
title: {text: 'values'}
},
//Whether to use Highstocks instead of Highcharts (optional). Defaults to false.
useHighStocks: false,
//size (optional) if left out the chart will default to size of the div or something sensible.
size: {
width: 400,
height: 300
},
//function (optional)
// func: function (chart) {
// //setup some logic for the chart
// }
};
}
【问题讨论】:
-
你能告诉我们$scope.chartConfig里面的选项吗?
-
@DaniloVelasquez 请参阅上面的配置。
标签: angularjs jhipster highcharts-ng