我在我的应用程序中使用了highcharts-ng和angular js。对于一个简单的例子,我能够调用一个rest服务,并能够使用它绘制图形。但在我的场景中,使用相同的表单输入,我需要调用两个rest服务,并根据两个响应同时绘制两个图表(即第一个响应的第一个图和另一个响应的第二个图。我尝试了一些情况,但我只能绘制一个图表,如果我尝试绘制另一个图表,则整个页面都会重置。有没有关于如何做的帮助。
发布于 2015-02-03 14:09:20
这是我解决你的问题的方法。我觉得没问题。
第一步:在服务时创建drawChart
angular.module('chartApp')
.factory('drawChart', function () {
return {
lineChart: function (args) {
// Draw charts
var charts = [],
chart;
// agrs: this is variable mutable
var maps = args.maps,
color = args.color,
width = args.width,
height = args.height,
lablesY = args.lablesY,
lablesX = args.lablesX,
title = args.title;
angular.forEach(maps, function (map) {
chart = {
animation: true,
options: {
legend: {
enabled: false
}
},
title: title,
series: [{
data: map,
enableMouseTracking: false,
color: color,
marker: {
enabled: false
}
}],
loading: false,
yAxis: {
currentMin: 0,
currentMax: 100,
lineColor: '#cacaca',
lineWidth: 1,
gridLineWidth: null,
labels: lablesY,
title: null
},
xAxis: {
currentMin: 0,
labels: lablesX,
lineColor: '#cacaca',
lineWidth: 1,
tickWidth: 0
},
size: {
width: width,
height: height
}
};
charts.push(chart);
});
return charts;
}
};
});第二,在你的控制器上调用它
// Draw charts
var chartArgs = {
maps: $scope.maps,
color: '#0ec679',
width: 245,
height: 125,
lablesY: {
enabled: false,
},
lablesX: {
enabled: false,
},
title: {
text: ''
}
};
if (Object.keys($scope.maps).length != 0) {
$scope.chartMaps = drawChart.lineChart(chartArgs);
} 视图中的第三
<highchart config="chartMaps[$index]"></highchart>
发布于 2016-09-24 06:59:44
以下是我的解决方案:
Javascript:
// first chart
$scope.chartConfig1 = {
chart: {
type: 'bar'
},
title: {
text: 'Fruit Consumption'
}, ...
};
// second chart
$scope.chartConfig2 = {
chart: {
type: 'line'
},
title: {
text: 'Fruit Consumption'
}, ...
};HTML:
<!-- first chart -->
<div id="chartA">
<highchart id="chart1" config="chartConfig1"></highchart>
</div>
<!-- second chart -->
<div id="chartB">
<highchart id="chart2" config="chartConfig2"></highchart>
</div>你可以无限地重复这个范例。
https://stackoverflow.com/questions/19195010
复制相似问题