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).4---56# Chart Config Generator78## Prerequisites & Dependencies9- Node.js 18+ or Python 3.10+ 10- Mandatory packages (choose one):11 - JavaScript: `npm i chart.js`12 - Python: `pip install matplotlib seaborn plotly`13- A raw JSON dataset with numeric values and categorical labels1415## Execution Steps161. Load or define the raw JSON dataset: an array of objects with at least one numeric `value` field and one categorical `label`/`category` field172. Determine the chart type based on the data shape:18 - Bar chart: compare categories19 - Line chart: show trends over time20 - Pie/Doughnut: show part-to-whole ratios213. Map dataset fields to chart configuration:22 - X-axis: categorical label field23 - Y-axis: numeric value field24 - Tooltip/custom label: additional fields as needed254. Generate the chart configuration object:26 - **Chart.js**: `{ type: 'bar', data: { labels: [...], datasets: [{ label: '...', data: [...] }] }, options: { ... } }`27 - **Recharts**: `<BarChart data={...}><Bar dataKey="value" name="..." /></BarChart>`28 - **ECharts**: `option: { xAxis: { data: [...] }, yAxis: { type: 'value' }, series: [{ name: '...', type: 'bar', data: [...] }] }`295. Customize colors, legends, and responsive settings per the chosen library's API306. Render the chart in your frontend or export as image/PDF using library-specific methods3132```javascript33// Example: Chart.js configuration from raw JSON34const rawData = [35 { category: 'January', value: 65 },36 { category: 'February', value: 59 },37 { category: 'March', value: 80 },38 { category: 'April', value: 81 },39 { category: 'May', value: 56 },40];4142const chartConfig = {43 type: 'bar',44 data: {45 labels: rawData.map(item => item.category),46 datasets: [{47 label: 'Sales',48 backgroundColor: 'rgba(54, 162, 235, 0.5)',49 borderColor: 'rgba(54, 162, 235, 1)',50 data: rawData.map(item => item.value),51 }],52 },53 options: {54 responsive: true,55 plugins: {56 legend: { position: 'bottom' },57 title: { display: true, text: 'Monthly Sales' },58 },59 scales: {60 y: { beginAtZero: true },61 },62 },63};6465export default chartConfig;66```6768```bash69# Render with Chart.js (HTML canvas)70const ctx = document.getElementById('myChart').getContext('2d');71new Chart(ctx, chartConfig);72```