Javascript 自定义指令的单选按钮
我有一个指令,使highcharts区域样条曲线图成为一个可重用元素,如下所示:Javascript 自定义指令的单选按钮,javascript,angularjs,highcharts,Javascript,Angularjs,Highcharts,我有一个指令,使highcharts区域样条曲线图成为一个可重用元素,如下所示: angular.module('statisticsApp') .directive('stockchart', function ($http) { return { transclude: true, template: '<div></div>', restrict: 'E',
angular.module('statisticsApp')
.directive('stockchart', function ($http) {
return {
transclude: true,
template: '<div></div>',
restrict: 'E',
scope: {},
link: function postLink(scope, element, attrs) {
// scope.country=attrs.country;
var type=attrs.type;
var currencies=attrs.currencies;
var baseRestUrl="http://mydomain/background/rest/statistics";
var realUrl=baseRestUrl + "/" + type;
if (type == "equity") {
realUrl += "/" + scope.country;
scope.header="Equity per day - " + scope.country;
}
// alert(realUrl);
$http.get(realUrl).then(
function successCallback(response){
var equity = response.data;
var arrayLength = equity.length;
var serie = {
name: scope.country,
data: []
}
var categories = [];
for ( var i = 0; i < arrayLength; i+=1) {
var seriesName = equity[i][2];
var currency = equity[i][3];
var date = equity[i][0];
var amount = equity[i][1];
if ( currency == "EUR") {
serie["data"].push(amount);
categories.push(date);
}
}
var series = [];
series.push(serie);
element.highcharts({
chart: {
type: "areaspline"
},
title: {
text: scope.header
},
legend: {
layout: "vertical",
align: "left",
verticalAlign: "top",
x: 150,
y: 100,
floating: true,
borderWidth: 1,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || "#FFFFFF"
},
tooltip:{
valueDecimals : 2
},
yAxis: {
title: {
text: 'Amount'
}
},
xAxis: {
categories: categories
},
series: series
});
},
function errorCallBack(response){
equity = ["It", "did", "not", "work"];
}
);
}
};
});
角度模块('statisticsApp')
.directive('stockchart',函数($http){
返回{
是的,
模板:“”,
限制:'E',
作用域:{},
链接:函数postLink(范围、元素、属性){
//scope.country=attrs.country;
var type=attrs.type;
var货币=属性货币;
var baseRestUrl=”http://mydomain/background/rest/statistics";
var realUrl=baseRestUrl+“/”+类型;
如果(类型=“权益”){
realUrl+=“/”+scope.country;
scope.header=“每日权益-”+scope.country;
}
//警报(realUrl);
$http.get(realUrl)。然后(
函数成功回调(响应){
var equity=响应数据;
var arrayLength=股权长度;
变量系列={
名称:scope.country,
数据:[]
}
var类别=[];
对于(变量i=0;i<div>
<form>
<h3>Currency</h3>
<input type="radio" ng-model="currency" name="currency" value="EUR"> EUR<br/>
<input type="radio" ng-model="currency" name="currency" value="USD"> USD<br/>
Other: <input type="text" ng-model="currency" name="currency" value=""><br/>
</form>
<form>
<h3>Country</h3>
<input type="radio" ng-model="country" name="country" value="BE"> BE<br/>
<input type="radio" ng-model="country" name="country" value="NL"> NL<br/>
<input type="radio" ng-model="country" name="country" value="FI"> FI<br/>
<input type="radio" ng-model="country" name="country" value="CZ"> CZ<br/>
<input type="radio" ng-model="country" name="country" value="DE"> DE<br/>
<input type="radio" ng-model="country" name="country" value="FR"> FR<br/>
</form>
<stockchart country="BE" type="equity" currencies="EUR"></stockchart>
<stockchart country="NL" type="equity" currencies="EUR"></stockchart>
</div>
通货
欧元
美元
其他:
国家
是
NL
FI
CZ
DE
FR
我希望能够将最后一行减少到1行:
或者是同样全球化的东西