Sha256: cceb8d54910262a483df7066655d2b06c442d708c10c8071420319ba32c321c5

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

(function() {
    "use strict";
    window.Suricate = window.Suricate || {};
    Chart.defaults.global.responsive = true;
    Chart.defaults.global.animation  = false;

    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

2 entries across 2 versions & 1 rubygems

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