Download web/Chart.js/pie/chart_0059_pie.html from chartact-benchmark/ChartAct: direct link, hf CLI and curl.
- Browser
- Download file 3.38 kB
-
https://huggingface.co/datasets/chartact-benchmark/ChartAct/resolve/main/web/Chart.js/pie/chart_0059_pie.html
- Command line
-
hf download hf://datasets/chartact-benchmark/ChartAct/web/Chart.js/pie/chart_0059_pie.html
-
curl -L -o chart_0059_pie.html https://huggingface.co/datasets/chartact-benchmark/ChartAct/resolve/main/web/Chart.js/pie/chart_0059_pie.html
3.38 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>Pie Chart</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>Pie Chart</h1> | |
| <div id="legend-container"></div> | |
| <div id="chart-wrap"> | |
| <canvas id="chart"></canvas> | |
| </div> | |
| <script type="text/plain" data-chart-inline="true"> | |
| const DATA_COUNT = 5; | |
| Utils.srand(110); | |
| const __generatedDataValues = [[19.41615226, -89.00805898, 81.37431413, 14.51388889, -35.26834705]]; | |
| let __generatedDataIndex = 0; | |
| function generateData() { | |
| const value = __generatedDataValues[__generatedDataIndex] ?? __generatedDataValues[__generatedDataValues.length - 1]; | |
| __generatedDataIndex += 1; | |
| return JSON.parse(JSON.stringify(value)); | |
| } | |
| const data = { | |
| datasets: [{ | |
| data: generateData() | |
| }] | |
| }; | |
| function colorize(opaque, hover, ctx) { | |
| const v = ctx.parsed; | |
| const c = v < -50 ? '#D60000' | |
| : v < 0 ? '#F46300' | |
| : v < 50 ? '#0358B6' | |
| : '#44DE28'; | |
| const opacity = hover ? 1 - Math.abs(v / 150) - 0.2 : 1 - Math.abs(v / 150); | |
| return opaque ? c : Utils.transparentize(c, opacity); | |
| } | |
| function hoverColorize(ctx) { | |
| return colorize(false, true, ctx); | |
| } | |
| const config = { | |
| type: 'pie', | |
| data: data, | |
| options: { | |
| plugins: { | |
| legend: false, | |
| tooltip: false, | |
| }, | |
| elements: { | |
| arc: { | |
| backgroundColor: colorize.bind(null, false, false), | |
| hoverBackgroundColor: hoverColorize | |
| } | |
| } | |
| } | |
| }; | |
| 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_0059_pie.inline01.js"></script> | |
| </body> | |
| </html> | |