You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

chartjs-chart-timeline

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chartjs-chart-timeline

timeline chart type for chart.js

0.4.0
latest
Source
npmnpm
Version published
Weekly downloads
266
-73.77%
Maintainers
1
Weekly downloads
 
Created
Source

chartjs-chart-timeline

Timeline chart library for Chart.js.

"type": "timeline",
"options": {
    // Depricated and will be removed in future. Please use elements.* instead.
    // "colorFunction": function(text, data, dataset, index) {
    //     return Color('black');
    // },
    // "showText": true,
    // "textPadding": 4
    "elements": {
        "colorFunction": function(text, data, dataset, index) {
            return Color('black');
        },
        "showText": true,
        "textPadding": 4
    }
},
"data": {
    "labels": [
        "Cool Graph",
        "heater1"
    ],
    "datasets": [
        {
            "data": [
                [
                    "2018-01-22T16:00:00.000Z",
                    "2018-01-23T05:40:44.626Z",
                    "Unknown"
                ]
            ]
        },
        {
            "data": [
                [
                    "2018-01-22T16:00:00.000Z",
                    "2018-01-23T04:57:43.736Z",
                    "On"
                ],
                [
                    "2018-01-23T04:57:43.736Z",
                    "2018-01-23T04:57:55.437Z",
                    "Off"
                ],
                [
                    "2018-01-23T04:57:55.437Z",
                    "2018-01-23T05:40:44.626Z",
                    "On"
                ]
            ]
        }
    ]
},

Example for dynamic resize by dataset count:

resizeChart() {
    if (!this._chart) return;
    // Chart not ready
    if (this.$.chartTarget.clientWidth === 0) {
        if (this._resizeTimer === undefined) {
            this._resizeTimer = setInterval(this.resizeChart.bind(this), 10);
            return;
        }
    }

    clearInterval(this._resizeTimer);
    this._resizeTimer = undefined;

    this._resizeChart();
}

_resizeChart() {
    const chartTarget = this.$.chartTarget;

    const options = this.data;
    const data = options.data;

    if (data.datasets.length === 0) {
        return;
    }

    if (!this.isTimeline) {
        this._chart.resize();
        return;
    }

    // Recalculate chart height for Timeline chart
    var axis = this._chart.boxes.filter(x => x.position === 'bottom')[0];
    if (axis && axis.height > 0) {
        this._axisHeight = axis.height;
    }
    if (!this._axisHeight) {
        chartTarget.style.height = '100px';
        chartTarget.height = '100px';
        this._chart.resize();
        axis = this._chart.boxes.filter(x => x.position === 'bottom')[0];
        if (axis && axis.height > 0) {
            this._axisHeight = axis.height;
        }
    }
    if (this._axisHeight) {
        const cnt = data.datasets.length;
        const targetHeight = ((30 * cnt) + this._axisHeight) + 'px';
        if (chartTarget.style.height !== targetHeight) {
            chartTarget.style.height = targetHeight;
            chartTarget.height = targetHeight;
        }
        this._chart.resize();
    }
}

Usage: https://github.com/fanthos/chartjs-chart-timeline/wiki

Keywords

chartjs

FAQs

Package last updated on 19 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts