{"id":25337603,"url":"https://github.com/atomjoy/chartjs","last_synced_at":"2026-02-09T12:31:44.943Z","repository":{"id":272640152,"uuid":"917285840","full_name":"atomjoy/chartjs","owner":"atomjoy","description":"Chart.js line chart example with gradients, patterns and animations (Date time charts).","archived":false,"fork":false,"pushed_at":"2025-01-16T11:17:09.000Z","size":807,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-13T19:07:01.417Z","etag":null,"topics":["chartjs","date-time-chart","line-chart"],"latest_commit_sha":null,"homepage":"https://github.com/atomjoy/chartjs","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/atomjoy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-15T17:46:55.000Z","updated_at":"2025-03-19T18:14:01.000Z","dependencies_parsed_at":"2025-01-15T20:07:37.076Z","dependency_job_id":"20a7a427-e4d8-428c-81ed-4aaf585dc9d6","html_url":"https://github.com/atomjoy/chartjs","commit_stats":null,"previous_names":["atomjoy/chartjs"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/atomjoy/chartjs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomjoy%2Fchartjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomjoy%2Fchartjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomjoy%2Fchartjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomjoy%2Fchartjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atomjoy","download_url":"https://codeload.github.com/atomjoy/chartjs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomjoy%2Fchartjs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29265190,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-09T04:11:57.159Z","status":"ssl_error","status_checked_at":"2026-02-09T04:11:56.117Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chartjs","date-time-chart","line-chart"],"created_at":"2025-02-14T06:56:04.854Z","updated_at":"2026-02-09T12:31:44.925Z","avatar_url":"https://github.com/atomjoy.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chart.js Linear Date and Time Charts\nChart.js line chart example with gradients and animations.\n\n## Image\n\n\u003cimg src=\"https://raw.githubusercontent.com/atomjoy/chartjs/refs/heads/main/chart-js.png\" width=\"100%\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/atomjoy/chartjs/refs/heads/main/chart-js-1.png\" width=\"100%\"\u003e\n\n## Date time chart\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\n\u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\u003e\n    \u003ctitle\u003eDate Time Chart\u003c/title\u003e\n\n    \u003cscript src=\"https://cdn.jsdelivr.net/npm/chart.js\"\u003e\u003c/script\u003e\n    \u003cscript src=\"https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js\"\u003e\u003c/script\u003e\n\n    \u003cscript\u003e\n        let width, height, gradient;\n\n        function getGradient(ctx, chartArea) {\n            const chartWidth = chartArea.right - chartArea.left;\n            const chartHeight = chartArea.bottom - chartArea.top;\n            if (!gradient || width !== chartWidth || height !== chartHeight) {\n                // Create the gradient because this is either the first render\n                // or the size of the chart has changed\n                width = chartWidth;\n                height = chartHeight;\n                // Vertically\n                gradient = ctx.createLinearGradient(0, chartArea.bottom, 0, chartArea.top);\n                // Horizontally\n                gradient = ctx.createLinearGradient(chartArea.right, chartArea.top, chartArea.left, chartArea.top);\n                // Colors\n                gradient.addColorStop(0, '#f20')\n                gradient.addColorStop(0.5, '#ff0')\n                gradient.addColorStop(1, '#5c5')\n            }\n\n            return gradient;\n        }\n\n        function createDiagonalPattern(color = 'black') {\n            let shape = document.createElement('canvas')\n            shape.width = 10\n            shape.height = 10\n            let c = shape.getContext('2d')\n            c.strokeStyle = color\n            c.beginPath()\n            c.moveTo(2, 0)\n            c.lineTo(10, 8)\n            c.stroke()\n            c.beginPath()\n            c.moveTo(0, 8)\n            c.lineTo(2, 10)\n            c.stroke()\n            return c.createPattern(shape, 'repeat')\n        }\n\n        window.onload = () =\u003e {\n            // const labels = Utils.months({ count: DATA_COUNT });\n            const ctx = document.getElementById('myChart');\n\n            // Create a Gradient\n            const cnv = ctx.getContext('2d');\n\n            var gradient1 = cnv.createLinearGradient(0, 0, 0, 600);\n            gradient1.addColorStop(0, '#0099ff')\n            gradient1.addColorStop(0.6, '#0099ffaa')\n            gradient1.addColorStop(1, '#fff1')\n\n            const chart = new Chart(ctx, {\n                type: 'line',\n                data: {\n                    datasets: [{\n                        label: 'Year 2024',\n                        data: [{\n                            x: '2024-11-05 00:25:30',\n                            y: 50\n                        }, {\n                            x: '2024-11-06 01:00:28',\n                            y: 60\n                        }, {\n                            x: '2024-11-07 09:00:28',\n                            y: 20\n                        }, {\n                            x: '2024-11-08 11:00:28',\n                            y: 22\n                        }],\n                        tension: 0.3,\n                        borderWidth: 5,\n                        borderColor: function (context) {\n                            const chart = context.chart;\n                            const { ctx, chartArea } = chart;\n                            if (!chartArea) {\n                                // This case happens on initial chart load\n                                return;\n                            }\n                            return getGradient(ctx, chartArea);\n                        },\n                        backgroundColor: '#f251',\n                        pointStyle: 'circle',\n                        pointRadius: 5,\n                        pointHoverRadius: 10,\n                        fill: false,\n                        animations: {\n                            radius: {\n                                duration: 400,\n                                easing: 'linear',\n                                loop: (context) =\u003e context.active\n                            }\n                        },\n                        hoverRadius: 12,\n                        hoverBackgroundColor: '#f25',\n                        interaction: {\n                            mode: 'nearest',\n                            intersect: false,\n                            axis: 'x'\n                        },\n                    },\n                    {\n                        label: 'Year 2025',\n                        data: [{\n                            x: '2024-11-05 00:25:30',\n                            y: 22\n                        }, {\n                            x: '2024-11-06 01:00:28',\n                            y: 49\n                        }, {\n                            x: '2024-11-07 09:00:28',\n                            y: 26\n                        }, {\n                            x: '2024-11-08 11:00:28',\n                            y: 38\n                        }],\n                        tension: 0.3,\n                        borderWidth: 2,\n                        borderColor: '#0099ff',\n                        backgroundColor: '#0099ff11',\n                        pointStyle: 'circle',\n                        pointRadius: 5,\n                        pointHoverRadius: 10,\n                        fill: true,\n                        borderDash: [10, 5], // Dashed line style\n                        backgroundColor: gradient1,\n                        backgroundColor: createDiagonalPattern('#09f'),\n                        parsing: {\n                            // yAxisKey: 'nested.value'\n                        }\n                    }\n                    ]\n                },\n                options: {\n                    responsive: true,\n                    parsing: {\n                        // Parse data array\n                        // xAxisKey: 'id',\n                        // yAxisKey: 'nested.value',\n                        // key: 'nested.value'\n                    },\n                    scales: {\n                        y: {\n                            beginAtZero: true,\n                            grid: {\n                                // color: '#ccc',\n                                type: 'time',\n                                display: true,\n                                lineWidth: 1,\n                            },\n                            border: {\n                                // dash: [0, 0],\n                            },\n                            ticks: {\n                                // color: '#ccc',\n                                display: true,\n                                lineWidth: 1,\n                                callback: function (value) { return value + 'k'; }\n                            }\n                        },\n                        x: {\n                            type: 'timeseries',\n                            time: {\n                                unit: 'day',\n                                tooltipFormat: 'dd-MM-yyyy HH:mm:ss',\n                                displayFormats: {\n                                    hour: 'HH:MM',\n                                    day: 'dd-MM-yyyy'\n                                }\n                            },\n                            // min: '2024-11-04 00:00:00',\n                            // max: '2024-11-09 00:00:00',\n                            grid: {\n                                // color: '#ccc',\n                                display: true,\n                                lineWidth: 1,\n                            },\n                            border: {\n                                dash: [5, 5],\n                            },\n                            ticks: {\n                                display: true,\n                                // color: '#ccc',\n                            }\n                        }\n                    },\n                    plugins: {\n                        title: {\n                            display: true,\n                            text: 'Compare Orders',\n                            // text: (ctx) =\u003e 'Point Style: ' + ctx.chart.data.datasets[0].pointStyle,\n                            font: {\n                                size: 13,\n                                weight: 'normal',\n                                family: 'Poppins',\n                            },\n                        },\n                        legend: {\n                            display: true,\n                            align: 'start',\n                            position: 'bottom',\n                        }\n                    },\n                    animations: {\n                        radius: {\n                            duration: 400,\n                            easing: 'linear',\n                            loop: (context) =\u003e context.active\n                        }\n                    },\n                    hoverRadius: 12,\n                    hoverBackgroundColor: '#0099ff',\n                    interaction: {\n                        mode: 'nearest',\n                        intersect: false,\n                        axis: 'x'\n                    },\n                    onClick: (e) =\u003e {\n                        console.log(e);\n                    }\n                },\n            });\n        }\n    \u003c/script\u003e\n\n    \u003cstyle\u003e\n        @import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900\u0026display=swap');\n\n        body {\n            padding: 50px 50px;\n        }\n\n        body * {\n            font-family: Poppins, Arial, Helvetica, sans-serif;\n        }\n    \u003c/style\u003e\n\u003c/head\u003e\n\n\u003cbody\u003e\n    \u003cdiv id=\"statistics\"\u003e\n        \u003cdiv class=\"panel-subtitle\"\u003eStatistics\u003c/div\u003e\n        \u003ccanvas id=\"myChart\"\u003e\u003c/canvas\u003e\n    \u003c/div\u003e\n\u003c/body\u003e\n\n\u003c/html\u003e\n```\n\n## Patterns and Gradients\n\n### Image pattern\n\n```js\nconst img = new Image();\nimg.src = 'https://example.com/my_image.png';\nimg.onload = () =\u003e {\n  const ctx = document.getElementById('canvas').getContext('2d');\n  const fillPattern = ctx.createPattern(img, 'repeat');\n\n  const chart = new Chart(ctx, {\n    data: {\n      labels: ['Item 1', 'Item 2', 'Item 3'],\n      datasets: [{\n        data: [10, 20, 30],\n        backgroundColor: fillPattern\n      }]\n    }\n  });\n};\n```\n\n### Stripes pattern\n\n```js\nfunction createDiagonalPattern(color = 'green') {\n    let shape = document.createElement('canvas')\n    shape.width = 10\n    shape.height = 10\n    let c = shape.getContext('2d')\n    c.strokeStyle = color\n    c.beginPath()\n    c.moveTo(2, 0)\n    c.lineTo(10, 8)\n    c.stroke()\n    c.beginPath()\n    c.moveTo(0, 8)\n    c.lineTo(2, 10)\n    c.stroke()\n    return c.createPattern(shape, 'repeat')\n}\n\nconst chart = new Chart(ctx, {\n  type: 'bar',\n  data: {\n    labels: ['Item 1', 'Item 2', 'Item 3'],\n    datasets: [{\n      data: [10, 20, 30],\n      backgroundColor: createDiagonalPattern('#09f'),\n      fill: true,\n      tension: 0.3,\n      borderWidth: 2,\n      borderColor: '#09f',\n      backgroundColor: '#09f1',\n      pointStyle: 'circle',\n      pointRadius: 5,\n      pointHoverRadius: 10,\n    }]\n  }\n});\n```\n\n## Links\n- https://www.chartjs.org/docs/latest\n- https://www.chartjs.org/docs/latest/general/data-structures.html\n- https://www.chartjs.org/docs/latest/general/colors.html#patterns-and-gradients\n- https://www.chartjs3.com/docs/chart/getting-started\n- https://www.youtube.com/watch?v=DnjlLbOsPlM\n- https://www.youtube.com/watch?v=AEaXyzCElGI\n- https://www.youtube.com/watch?v=vmp3czGfw2U\n- https://www.youtube.com/watch?v=EVHi41f7psQ\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomjoy%2Fchartjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatomjoy%2Fchartjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomjoy%2Fchartjs/lists"}