Chart Config Generator
Prerequisites & Dependencies
- Node.js 18+ or Python 3.10+
- Mandatory packages (choose one):
- JavaScript:
npm i chart.js
- Python:
pip install matplotlib seaborn plotly
- A raw JSON dataset with numeric values and categorical labels
Execution Steps
- Load or define the raw JSON dataset: an array of objects with at least one numeric
value field and one categorical label/category field
- Determine the chart type based on the data shape:
- Bar chart: compare categories
- Line chart: show trends over time
- Pie/Doughnut: show part-to-whole ratios
- Map dataset fields to chart configuration:
- X-axis: categorical label field
- Y-axis: numeric value field
- Tooltip/custom label: additional fields as needed
- Generate the chart configuration object:
- Chart.js:
{ type: 'bar', data: { labels: [...], datasets: [{ label: '...', data: [...] }] }, options: { ... } }
- Recharts:
<BarChart data={...}><Bar dataKey="value" name="..." /></BarChart>
- ECharts:
option: { xAxis: { data: [...] }, yAxis: { type: 'value' }, series: [{ name: '...', type: 'bar', data: [...] }] }
- Customize colors, legends, and responsive settings per the chosen library's API
- Render the chart in your frontend or export as image/PDF using library-specific methods
// Example: Chart.js configuration from raw JSON
const rawData = [
{ category: 'January', value: 65 },
{ category: 'February', value: 59 },
{ category: 'March', value: 80 },
{ category: 'April', value: 81 },
{ category: 'May', value: 56 },
];
const chartConfig = {
type: 'bar',
data: {
labels: rawData.map(item => item.category),
datasets: [{
label: 'Sales',
backgroundColor: 'rgba(54, 162, 235, 0.5)',
borderColor: 'rgba(54, 162, 235, 1)',
data: rawData.map(item => item.value),
}],
},
options: {
responsive: true,
plugins: {
legend: { position: 'bottom' },
title: { display: true, text: 'Monthly Sales' },
},
scales: {
y: { beginAtZero: true },
},
},
};
export default chartConfig;
# Render with Chart.js (HTML canvas)
const ctx = document.getElementById('myChart').getContext('2d');
new Chart(ctx, chartConfig);
1---2name: chart-config-generator3description: Map raw JSON datasets into ready-to-use chart configuration objects (Chart.js, Recharts, or ECharts).4metadata:5 source: skills/chart-config-generator/chart-config-generator.md6---78# Chart Config Generator910## Prerequisites & Dependencies11- Node.js 18+ or Python 3.10+ 12- Mandatory packages (choose one):13 - JavaScript: `npm i chart.js`14 - Python: `pip install matplotlib seaborn plotly`15- A raw JSON dataset with numeric values and categorical labels1617## Execution Steps181. Load or define the raw JSON dataset: an array of objects with at least one numeric `value` field and one categorical `label`/`category` field192. Determine the chart type based on the data shape:20 - Bar chart: compare categories21 - Line chart: show trends over time22 - Pie/Doughnut: show part-to-whole ratios233. Map dataset fields to chart configuration:24 - X-axis: categorical label field25 - Y-axis: numeric value field26 - Tooltip/custom label: additional fields as needed274. Generate the chart configuration object:28 - **Chart.js**: `{ type: 'bar', data: { labels: [...], datasets: [{ label: '...', data: [...] }] }, options: { ... } }`29 - **Recharts**: `<BarChart data={...}><Bar dataKey="value" name="..." /></BarChart>`30 - **ECharts**: `option: { xAxis: { data: [...] }, yAxis: { type: 'value' }, series: [{ name: '...', type: 'bar', data: [...] }] }`315. Customize colors, legends, and responsive settings per the chosen library's API326. Render the chart in your frontend or export as image/PDF using library-specific methods3334```javascript35// Example: Chart.js configuration from raw JSON36const rawData = [37 { category: 'January', value: 65 },38 { category: 'February', value: 59 },39 { category: 'March', value: 80 },40 { category: 'April', value: 81 },41 { category: 'May', value: 56 },42];4344const chartConfig = {45 type: 'bar',46 data: {47 labels: rawData.map(item => item.category),48 datasets: [{49 label: 'Sales',50 backgroundColor: 'rgba(54, 162, 235, 0.5)',51 borderColor: 'rgba(54, 162, 235, 1)',52 data: rawData.map(item => item.value),53 }],54 },55 options: {56 responsive: true,57 plugins: {58 legend: { position: 'bottom' },59 title: { display: true, text: 'Monthly Sales' },60 },61 scales: {62 y: { beginAtZero: true },63 },64 },65};6667export default chartConfig;68```6970```bash71# Render with Chart.js (HTML canvas)72const ctx = document.getElementById('myChart').getContext('2d');73new Chart(ctx, chartConfig);74```