Download web/Chart.js/line/chart_0057_line.html from chartact-benchmark/ChartAct: direct link, hf CLI and curl.
- Browser
- Download file 3.78 kB
-
https://huggingface.co/datasets/chartact-benchmark/ChartAct/resolve/main/web/Chart.js/line/chart_0057_line.html
- Command line
-
hf download hf://datasets/chartact-benchmark/ChartAct/web/Chart.js/line/chart_0057_line.html
-
curl -L -o chart_0057_line.html https://huggingface.co/datasets/chartact-benchmark/ChartAct/resolve/main/web/Chart.js/line/chart_0057_line.html
3.78 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>Linear Gradient</title> | |
| <style> | |
| :root { | |
| color-scheme: light; | |
| } | |
| body { | |
| margin: 0; | |
| padding: 20px; | |
| font-family: Segoe UI, Arial, sans-serif; | |
| background: #f5f7fb; | |
| color: #1f2a37; | |
| } | |
| h1 { | |
| margin: 0 0 10px 0; | |
| font-size: 20px; | |
| font-weight: 600; | |
| } | |
| #legend-container { | |
| margin-bottom: 8px; | |
| } | |
| #chart-wrap { | |
| position: relative; | |
| width: min(1100px, 100%); | |
| height: 520px; | |
| background: #ffffff; | |
| border: 1px solid #e2e8f0; | |
| border-radius: 10px; | |
| padding: 12px; | |
| box-sizing: border-box; | |
| } | |
| #chart { | |
| width: 100%; | |
| height: 100%; | |
| } | |
| </style> | |
| <script src="./luxon.min.js"></script> | |
| <script src="./chart.umd.min.js"></script> | |
| <script src="./chartjs-adapter-luxon.umd.min.js"></script> | |
| </head> | |
| <body> | |
| <h1>Linear Gradient</h1> | |
| <div id="legend-container"></div> | |
| <div id="chart-wrap"> | |
| <canvas id="chart"></canvas> | |
| </div> | |
| <script type="text/plain" data-chart-inline="true"> | |
| let width, height, gradient; | |
| function getGradient(ctx, chartArea) { | |
| const chartWidth = chartArea.right - chartArea.left; | |
| const chartHeight = chartArea.bottom - chartArea.top; | |
| if (!gradient || width !== chartWidth || height !== chartHeight) { | |
| // Create the gradient because this is either the first render | |
| // or the size of the chart has changed | |
| width = chartWidth; | |
| height = chartHeight; | |
| gradient = ctx.createLinearGradient(0, chartArea.bottom, 0, chartArea.top); | |
| gradient.addColorStop(0, Utils.CHART_COLORS.blue); | |
| gradient.addColorStop(0.5, Utils.CHART_COLORS.yellow); | |
| gradient.addColorStop(1, Utils.CHART_COLORS.red); | |
| } | |
| return gradient; | |
| } | |
| const DATA_COUNT = 7; | |
| const NUMBER_CFG = {count: DATA_COUNT, min: -100, max: 100}; | |
| const labels = ["January", "February", "March", "April", "May", "June", "July"]; | |
| const data = { | |
| labels: labels, | |
| datasets: [ | |
| { | |
| label: 'Dataset 1', | |
| data: [-40.89420439, -68.86574074, 53.57424554, -26.66066529, 85.49125514, 22.12877229, 74.60991084], | |
| borderColor: function(context) { | |
| const chart = context.chart; | |
| const {ctx, chartArea} = chart; | |
| if (!chartArea) { | |
| // This case happens on initial chart load | |
| return; | |
| } | |
| return getGradient(ctx, chartArea); | |
| }, | |
| }, | |
| ] | |
| }; | |
| const config = { | |
| type: 'line', | |
| data: data, | |
| options: { | |
| responsive: true, | |
| plugins: { | |
| legend: { | |
| position: 'top', | |
| }, | |
| } | |
| }, | |
| }; | |
| function forceEnableHoverTooltip(chartConfig) { | |
| if (!chartConfig || typeof chartConfig !== 'object') { | |
| return; | |
| } | |
| if (!chartConfig.options || typeof chartConfig.options !== 'object') { | |
| chartConfig.options = {}; | |
| } | |
| const options = chartConfig.options; | |
| if (!options.plugins || typeof options.plugins !== 'object') { | |
| options.plugins = {}; | |
| } | |
| const plugins = options.plugins; | |
| if (plugins.tooltip === false) { | |
| plugins.tooltip = {}; | |
| } | |
| if (!plugins.tooltip || typeof plugins.tooltip !== 'object') { | |
| plugins.tooltip = {}; | |
| } | |
| const hasExternalTooltip = typeof plugins.tooltip.external === 'function'; | |
| if (!hasExternalTooltip) { | |
| plugins.tooltip.enabled = true; | |
| } | |
| } | |
| forceEnableHoverTooltip(config); | |
| const sampleCanvas = document.getElementById('chart'); | |
| const sampleChart = new Chart(sampleCanvas, config); | |
| </script> | |
| <script src="./chart_0057_line.inline01.js"></script> | |
| </body> | |
| </html> | |