AngularJS Chart

0

Я использую Angular Chart для создания шести диаграмм (баров и линий) на веб-сайте с различными мерами.

Поэтому я пытаюсь получить тип диаграммы из json файла и загрузить его в класс canvas, но это не работает:

{
    "modules": [{
        "name": "Chart1",
        "color": "color:red;",
        "type": "chart-bar",
        "series": "SeriesA",
        "daten": [["90", "99", "20", "21", "26", "75", "60", "67", "59", "55"]],
        "labels": ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10"],
        "colours": [{
            "fillColor": "rgba(224, 108, 112, 1)",
            "strokeColor": "rgba(207,100,103,1)",
            "pointColor": "rgba(220,220,220,1)",
            "pointStrokeColor": "#fff",
            "pointHighlightFill": "#fff",
            "pointHighlightStroke": "rgba(151,187,205,0.8)"
        }]
    }]
}

<div class="graph-display" ng-controller="jsonServerBox">
    <div class="bar-chart-box" ng-repeat="module in ocw.modules" width="100px"><div style="{{module.color}}">{{module.name}} </div>       
        <canvas class="{{module.type}}" data="module.daten" labels="module.labels" series="module.series"></canvas>
    </div>
</div>

Может ли кто-нибудь помочь мне решить это?

btw: без {{}} это не сработало

  • 0
    Вы добавили в свой модуль зависимость chart.js? var app = angular.module ("Bar_Chart", ["chart.js"]);
  • 0
    Да, модуль доступен - поэтому, когда я изменяю класс холста на "class = 'chart-bar'", тогда он работает нормально. Но я не хочу повторять урок холста шесть раз ...
Показать ещё 2 комментария
Теги:
charts

1 ответ

0

Это решение. Измените элемент холста следующим образом:

"modules": [{
                "name": "Chart1",
                "color": "color:red;",
                "type": "Line",
                "series": "SeriesA",
                "daten": [["90", "99", "20", "21", "26", "75", "60", "67", "59", "55"]],
                "labels": ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10"],
                "colours": [{ 
                    "fillColor": "rgba(224, 108, 112, 1)",
                    "strokeColor": "rgba(207,100,103,1)",
                    "pointColor": "rgba(220,220,220,1)",
                    "pointStrokeColor": "#fff",
                    "pointHighlightFill": "#fff",
                    "pointHighlightStroke": "rgba(151,187,205,0.8)"
                }]

<div style="height:400px;width:400px;">
<div class="graph-display" ng-controller="jsonServerBox">
    <div class="bar-chart-box" ng-repeat="module in ocw.modules" width="100px"><div style="{{module.color}}">{{module.name}} </div>       
         <canvas id="base" class="chart chart-base" chart-type="module.type" chart-data="module.daten" chart-labels="module.labels" chart-series="module.series"></canvas>
    </div>
</div>

Ещё вопросы

Сообщество Overcoder
Наверх
Меню