Sha256: 6408843c67652399cd1055b146ea3f4ea022db8bffbabb0c2379d99802449daf

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

(function() {
    "use strict";
    window.Suricate = window.Suricate || {};

    Suricate.ChartJSChartFactory = function() {

    };

    Suricate.ChartJSChartFactory.prototype.createLineChart = function(container, options) {
        var chart = {};
        var libraryObject;

        var convertData = function(data) {
            var datasets = [];
            for (var index = 0, seriesCount = data.series.length; index < seriesCount; index++) {
                var serie = data.series[index];
                datasets.push({
                    label: serie.name,
                    strokeColor: serie.color,
                    fillColor: "rgba(0, 0, 0, 0)",
                    pointStrokeColor: serie.color,
                    pointColor: serie.color,
                    data: serie.values
                });
            }

            return {
                labels: data.labels,
                datasets: datasets
            };
        };

        var init = function(data, options) {
            var ctx       = container.find(".chart")[0].getContext("2d");
            libraryObject = new Chart(ctx).Line(data, options);
            var legend    = libraryObject.generateLegend();
            container.find(".legend").html(legend);
        };

        var data = {
            labels: [],
            datasets: [ { } ]
        };
        init(data, options);

        chart.update = function(data) {
            var chartJSData = convertData(data);
            libraryObject.destroy();
            init(chartJSData, options);
        };

        return chart;
    };
}());

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
suricate-0.0.2 lib/suricate/generator/assets/javascript/chart-js-chart-factory.js