Amcharts Angular 指令

Amcharts Angular Directive

我找到了这个 angular 指令 Directive

但是当我创建两个相同的图表时它崩溃了,我无法添加图表。

问题是指令,生成随机id。

有没有办法直接写在scope里面?

谢谢!

更新(1)

我有一组图表: 例如

$scope.charts = [
{
    name:"Simple Pie Chart",
    image:"/theme2/assets/img/widget2.png",
    "struct":{
        "type": "pie",
        "balloonText": "[[title]]<br><span style='font-size:14px'><b>[[value]]</b> ([[percents]]%)</span>",
        "titleField": "category",
        "valueField": "column-1",
        "allLabels": [],
        "balloon": {},
        "titles": [],
        "data": [
            {
                "category": "category 1",
                "column-1": 8
            },
            {
                "category": "category 2",
                "column-1": 6
            },
            {
                "category": "category 3",
                "column-1": 2
            }
        ]
    }
}

当用户 select 其中一张图表时,我将其添加到变量中->

$scope.items.push(data.item); //chart selected

然后在 html 中显示 selected 图表
Directive :

 <div ng-repeat="graph in items">
                 <amchart  ng-model="graph" >
                </amchart>

            </div>

我猜 ng-repeat 崩溃是因为重复的项目...而不是图表

尝试ng-repeat="graph in items track by $index"

这将允许您在中继器中拥有重复的对象。