Javascript 从表angularjs获取highcharts数据
我正在尝试使用angularJS从html表中获取highcharts数据 这里是html:Javascript 从表angularjs获取highcharts数据,javascript,jquery,angularjs,highcharts,Javascript,Jquery,Angularjs,Highcharts,我正在尝试使用angularJS从html表中获取highcharts数据 这里是html: <table class="table-count" id="table-count"> <thead> <tr> <th> Priority </th> <th> Total </th> <th>
<table class="table-count" id="table-count">
<thead>
<tr>
<th>
Priority
</th>
<th>
Total
</th>
<th>
Active
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<span class="color-P0"></span> P0
</td>
<td ng-model="countPriority">
{{getCount("P0")}}
</td>
<td ng-model="countPriorityActive">
{{getCountActive("P0")}}
</td>
</tr>
<tr>
<td>
<span class="color-P1"></span>P1
</td>
<td ng-model="countPriority">
{{getCount("P1")}}
</td>
<td ng-model="countPriorityActive">
{{getCountActive("P1")}}
</td>
</tr>
<tr>
<td>
<span class="color-P2"></span>P2
</td>
<td ng-model="countPriority">
{{getCount("P2")}}
</td>
<td ng-model="countPriorityActive">
{{getCountActive("P2")}}
</td>
</tr>
<tr>
<td>
<span class="color-P3"></span>P3
</td>
<td ng-model="countPriority">
{{getCount("P3")}}
</td>
<td ng-model="countPriorityActive">
{{getCountActive("P3")}}
</td>
</tr>
</tbody>
</table>
.directive('hcPie1', function() {
return {
restrict: 'C',
replace: true,
scope: {
items: '='
},
controller: function($scope, $element) {},
template: '<div id="container1" style="margin: 0 auto">not working</div>',
link: function(scope, element, attrs) {
var chart = new Highcharts.Chart({
data: {
table: document.getElementById('table-count')
},
chart: {
renderTo: 'container1',
backgroundColor: '#afafaf',
plotBorderWidth: null,
plotShadow: false,
margin: [0, 0, 0, 0],
spacingTop: 0,
spacingBottom: 0,
spacingLeft: 0,
spacingRight: 0,
},
title: {
text: null
},
plotOptions: {
pie: {
size: '100%',
allowPointSelect: false,
cursor: 'pointer',
dataLabels: {
enabled: false
}
}
},
tooltip: {
enabled: false
},
labels: {
enabled: false
},
showInLegend: false,
series: [{
type: 'pie',
name: 'Browser share'
}],
exporting: {
enabled: false
}
});
}
}
});
优先
全部的
活跃的
P0
{{getCount(“P0”)}
{{getCountActive(“P0”)}
P1
{{getCount(“P1”)}
{{getCountActive(“P1”)}
P2
{{getCount(“P2”)}
{{getCountActive(“P2”)}
P3
{{getCount(“P3”)}
{{getCountActive(“P3”)}
和指令:
<table class="table-count" id="table-count">
<thead>
<tr>
<th>
Priority
</th>
<th>
Total
</th>
<th>
Active
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<span class="color-P0"></span> P0
</td>
<td ng-model="countPriority">
{{getCount("P0")}}
</td>
<td ng-model="countPriorityActive">
{{getCountActive("P0")}}
</td>
</tr>
<tr>
<td>
<span class="color-P1"></span>P1
</td>
<td ng-model="countPriority">
{{getCount("P1")}}
</td>
<td ng-model="countPriorityActive">
{{getCountActive("P1")}}
</td>
</tr>
<tr>
<td>
<span class="color-P2"></span>P2
</td>
<td ng-model="countPriority">
{{getCount("P2")}}
</td>
<td ng-model="countPriorityActive">
{{getCountActive("P2")}}
</td>
</tr>
<tr>
<td>
<span class="color-P3"></span>P3
</td>
<td ng-model="countPriority">
{{getCount("P3")}}
</td>
<td ng-model="countPriorityActive">
{{getCountActive("P3")}}
</td>
</tr>
</tbody>
</table>
.directive('hcPie1', function() {
return {
restrict: 'C',
replace: true,
scope: {
items: '='
},
controller: function($scope, $element) {},
template: '<div id="container1" style="margin: 0 auto">not working</div>',
link: function(scope, element, attrs) {
var chart = new Highcharts.Chart({
data: {
table: document.getElementById('table-count')
},
chart: {
renderTo: 'container1',
backgroundColor: '#afafaf',
plotBorderWidth: null,
plotShadow: false,
margin: [0, 0, 0, 0],
spacingTop: 0,
spacingBottom: 0,
spacingLeft: 0,
spacingRight: 0,
},
title: {
text: null
},
plotOptions: {
pie: {
size: '100%',
allowPointSelect: false,
cursor: 'pointer',
dataLabels: {
enabled: false
}
}
},
tooltip: {
enabled: false
},
labels: {
enabled: false
},
showInLegend: false,
series: [{
type: 'pie',
name: 'Browser share'
}],
exporting: {
enabled: false
}
});
}
}
});
指令('hcPie1',函数(){
返回{
限制:“C”,
替换:正确,
范围:{
项目:'='
},
控制器:函数($scope,$element){},
模板:“不工作”,
链接:函数(范围、元素、属性){
var图表=新的Highcharts.图表({
数据:{
表:document.getElementById('table-count')
},
图表:{
renderTo:'container1',
背景颜色:“#afafaf”,
plotBorderWidth:null,
影子:错,
边距:[0,0,0,0],
间距:0,
间距底部:0,
间距:0,
间距:0,
},
标题:{
文本:空
},
打印选项:{
馅饼:{
大小:“100%”,
allowPointSelect:false,
光标:“指针”,
数据标签:{
已启用:false
}
}
},
工具提示:{
已启用:false
},
标签:{
已启用:false
},
showInLegend:false,
系列:[{
键入“pie”,
名称:“浏览器共享”
}],
出口:{
已启用:false
}
});
}
}
});
以下是我使用的示例:
但它不起作用,
我错过了什么?我想你没有正确地附上图表。在本例中,有$(“#container”).highcharts({………该图表附加到特定的容器元素,在您的示例中,您只是将元素附加到数据源。此外,该图表还有一个构造函数,它接受您可以看到的选项和图表配置,只需将type=“pie”设置为type=“bar”您也可以在上看到详细的文档和配置,我希望这将有助于解决您的问题 在配置中应该是这样的
angular.module('myApp', [])
.directive('hcPie', function () {
return {
restrict: 'C',
replace: true,
scope: {
items: '='
},
controller: function ($scope, $element, $attrs) {
console.log(2);
},
template: '<div id="container" style="margin: 0 auto">not working</div>',
link: function (scope, element, attrs) {
console.log(3);
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2010'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage}%</b>',
percentageDecimals: 1
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function () {
return '<b>' + this.point.name + '</b>: ' + this.percentage + ' %';
}
}
}
},
series: [{
type: 'bar',
name: 'Browser share',
data: scope.items
}]
});
scope.$watch("items", function (newValue) {
chart.series[0].setData(newValue, true);
}, true);
}
}
});
angular.module('myApp',[])
.指令('hcPie',函数(){
返回{
限制:“C”,
替换:正确,
范围:{
项目:'='
},
控制器:函数($scope、$element、$attrs){
控制台日志(2);
},
模板:“不工作”,
链接:函数(范围、元素、属性){
控制台日志(3);
var图表=新的Highcharts.图表({
图表:{
renderTo:'容器',
plotBackgroundColor:null,
plotBorderWidth:null,
plotShadow:false
},
标题:{
正文:“2010年特定网站的浏览器市场份额”
},
工具提示:{
pointFormat:“{series.name}:{point.percentage}%”,
百分比小数:1
},
打印选项:{
馅饼:{
allowPointSelect:true,
光标:“指针”,
数据标签:{
启用:对,
颜色:'#000000',
连接器颜色:'#000000',
格式化程序:函数(){
返回“+this.point.name+”:“+this.percentage+”%”;
}
}
}
},
系列:[{
类型:'bar',
名称:“浏览器共享”,
数据:scope.items
}]
});
范围.$watch(“项目”),功能(newValue){
chart.series[0].setData(newValue,true);
},对);
}
}
});
我认为您没有正确附加图表。示例中有$(“#container”).highcharts({………图表被附加到特定的容器元素,在您的例子中,您只是将元素附加到数据源。此外,图表有一个构造函数,它接受您可以看到的选项和图表配置,只需将type=“pie”设置为type=“bar”您也可以在上看到详细的文档和配置,我希望这将有助于解决您的问题
在配置中应该是这样的
angular.module('myApp', [])
.directive('hcPie', function () {
return {
restrict: 'C',
replace: true,
scope: {
items: '='
},
controller: function ($scope, $element, $attrs) {
console.log(2);
},
template: '<div id="container" style="margin: 0 auto">not working</div>',
link: function (scope, element, attrs) {
console.log(3);
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2010'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage}%</b>',
percentageDecimals: 1
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function () {
return '<b>' + this.point.name + '</b>: ' + this.percentage + ' %';
}
}
}
},
series: [{
type: 'bar',
name: 'Browser share',
data: scope.items
}]
});
scope.$watch("items", function (newValue) {
chart.series[0].setData(newValue, true);
}, true);
}
}
});
angular.module('myApp',[])
.指令('hcPie',函数(){
返回{
限制:“C”,
替换:正确,
范围:{
项目:'='
},
控制器:函数($scope、$element、$attrs){
控制台日志(2);
},
模板:“不工作”,
链接:函数(范围、元素、属性){
控制台日志(3);
var图表=新的Highcharts.图表({
图表:{
renderTo:'容器',
plotBackgroundColor:null,
plotBorderWidth:null,
plotShadow:false
},
标题:{
正文:“2010年特定网站的浏览器市场份额”
},
工具提示:{
pointFormat:“{series.name}:{point.percentage}%”,
百分比小数:1
},
打印选项:{
馅饼:{
allowPointSelect:true,
光标:“指针”,
数据标签:{
启用:对,
颜色:'#000000',
连接器颜色:'#000000',
格式化程序:函数(){
返回“+this.point.name+”:“+this.percentage+”%”;
}
}
}
},
系列:[{
类型:'bar',
名称:“浏览器共享”,
数据:scope.items
}]
});
范围:$watch(“项目”),功能(新版本