VibeFox JS Charts — Demo
Avvio rapido
HTML semplice
Colonne del piano, una linea del consuntivo con marcatori e la sua linea della media. Passare il mouse sul grafico per il tooltip condiviso, fare clic su una colonna, fare clic su una voce della legenda per nascondere una serie, scorrere la rotella del mouse sull'area del grafico per lo zoom.
const chart = VibeFoxJSCharts.createChart('#app', {
title: 'Sales 2026',
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
series: [
{ name: 'Plan', type: 'column', data: [10, 12, 9, 14, 15, 13] },
{ name: 'Fact', type: 'line', data: [8, 14, 11, 13, 17, 16], markers: true, stats: ['avg'] },
],
yAxis: { title: 'k EUR' },
on: { pointClick: (e) => chart.setOptions({ subtitle: 'Clicked: ' + e.series.name + ', ' + e.point }) },
});Concetti di base
Serie e punti
Punti come semplici numeri (con un vuoto null il giovedì), come coppie [x, y] con i nomi delle categorie e come oggetti con la propria label e il proprio color.
VibeFoxJSCharts.createChart('#app', {
categories: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
series: [
{ name: 'Numbers', type: 'column', data: [5, 7, 6, null, 8, 9, 4] },
{ name: 'Pairs', type: 'line', markers: true, data: [['Mon', 3], ['Wed', 5], ['Fri', 4], ['Sun', 7]] },
{ name: 'Objects', type: 'line', markers: true, data: [
{ y: 2 }, { y: 3 }, { y: 2.5 }, { y: 4 },
{ y: 10, label: 'Best day', color: '#dc2626' },
{ y: 6 }, { y: 5 },
] },
],
});Eventi
La riga sotto il grafico mostra l'ultimo evento e il suo payload. Fare clic su un punto, fare clic su una voce della legenda, trascinare sull'area del grafico per lo zoom.
const output = document.createElement('p');
document.getElementById('app').after(output);
const chart = VibeFoxJSCharts.createChart('#app', {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug'],
series: [
{ name: 'Visitors', type: 'line', markers: true, data: [42, 45, 51, 49, 58, 63, 61, 67] },
{ name: 'Orders', type: 'column', data: [12, 14, 13, 17, 19, 18, 22, 24] },
],
});
output.textContent = 'Events appear here.';
chart.on('pointClick', (e) => { output.textContent = 'pointClick: ' + e.series.name + ', index ' + e.index + ', value ' + e.point; });
chart.on('seriesToggle', (e) => { output.textContent = 'seriesToggle: ' + e.id + ', hidden ' + e.hidden; });
chart.on('zoomChange', (e) => { output.textContent = 'zoomChange: ' + e.start.toFixed(2) + ' … ' + e.end.toFixed(2); });Snapshot dello stato
Ingrandire la vista, nascondere una serie e premere Save state; poi cambiare la vista (oppure premere Reset zoom) e premere Restore state. Il JSON salvato è mostrato sotto il grafico.
function addButton(text, onClick) {
const b = document.createElement('button');
b.textContent = text;
b.onclick = onClick;
document.getElementById('app').before(b);
}
const output = document.createElement('p');
document.getElementById('app').after(output);
const chart = VibeFoxJSCharts.createChart('#app', {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
series: [
{ id: 'north', name: 'North', data: [5, 6, 7, 8, 7, 9, 10, 9, 11, 12, 11, 13] },
{ id: 'south', name: 'South', data: [3, 4, 2, 5, 6, 5, 7, 6, 8, 7, 9, 10] },
],
});
let saved = null;
addButton('Save state', () => { saved = chart.getState(); output.textContent = JSON.stringify(saved); });
addButton('Restore state', () => saved && chart.setState(saved));
addButton('Reset zoom', () => { chart.resetZoom(); chart.showSeries('north'); chart.showSeries('south'); });
chart.setZoom(0.25, 0.75);
chart.hideSeries('south');Tipi di serie
Serie cartesiane
Scegliere un grafico nell'elenco: colonne impilate con una linea obiettivo, aree, barre, dispersione e bolle, una mappa di calore, un grafico a cascata, box plot, un istogramma, intervalli e un range sull'asse x (attività su righe).
const charts = {
'Stacked columns and a line': {
categories: ['Q1', 'Q2', 'Q3', 'Q4'],
stacked: true,
series: [
{ name: 'North', type: 'column', data: [5, 6, 7, 8], borderRadius: 4 },
{ name: 'South', type: 'column', data: [3, 4, 2, 5], pattern: 'diagonal' },
{ name: 'Target', type: 'line', data: [9, 9, 10, 12], stack: false, dash: [6, 4], smooth: true },
],
},
'Area and step line': {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug'],
series: [
{ name: 'Storage, TB', type: 'area', smooth: true, fillOpacity: 0.3, data: [12, 13, 15, 15, 17, 18, 20, 21] },
{ name: 'Plan, TB', type: 'line', step: true, data: [12, 12, 16, 16, 16, 20, 20, 24] },
],
},
'Bars': {
categories: ['Laptops', 'Phones', 'Tablets', 'Monitors', 'Printers'],
series: [{ name: 'Sales', type: 'bar', data: [1240, 980, 760, 640, 410], borderRadius: 3 }],
},
'Scatter and bubbles': {
xAxis: { title: 'Ad spend' }, yAxis: { title: 'Leads' },
tooltip: { shared: false },
series: [
{ name: 'Campaigns', type: 'scatter', data: [[12, 210], [18, 340], [25, 300], [31, 420], [40, 500], [44, 380], [52, 610]] },
{ name: 'Markets', type: 'bubble', data: [[20, 520, 30], [35, 250, 60], [48, 450, 20]] },
],
},
'Heatmap': {
xAxis: { categories: ['09:00', '11:00', '13:00', '15:00', '17:00'] },
yAxis: { categories: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'] },
series: [{ name: 'Tickets', type: 'heatmap', showValues: true, cellGap: 2,
data: Array.from({ length: 25 }, (_, i) => [i % 5, Math.floor(i / 5), (i * 37) % 23 + 2]) }],
},
'Waterfall': {
categories: ['Start', 'Sales', 'Services', 'Salaries', 'Rent', 'Result'],
series: [{ name: 'Cash', type: 'waterfall', data: [120, 80, 35, -90, -30, { sum: 'total' }] }],
},
'Box plot': {
categories: ['Team A', 'Team B', 'Team C'],
series: [{ name: 'Response time', type: 'boxplot', showMean: true, data: [
[12, 18, 22, 27, 35],
{ values: [10, 14, 15, 15, 16, 18, 19, 21, 22, 40] },
[8, 11, 13, 16, 20],
] }],
},
'Histogram': {
series: [{ name: 'Order value', type: 'histogram', bins: 10,
data: Array.from({ length: 300 }, (_, i) => 50 + ((i * 7919) % 101) * 0.6 + ((i * 104729) % 61) * 0.7) }],
},
'Ranges': {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
series: [
{ name: 'Temperature', type: 'rangeArea', data: [[-5, 3], [-3, 6], [1, 11], [5, 16], [9, 21], [13, 25]] },
{ name: 'Price', type: 'rangeColumn', data: [[2, 6], [3, 8], [4, 9], [6, 12], [7, 14], [9, 18]] },
],
},
'X-range': {
series: [{ name: 'Tasks', type: 'xrange', data: [
{ x: '2026-01-01', x2: '2026-01-12', y: 'Design', partialFill: 1 },
{ x: '2026-01-08', x2: '2026-01-28', y: 'Build', partialFill: 0.6 },
{ x: '2026-01-20', x2: '2026-02-05', y: 'Test', partialFill: 0.2 },
{ x: '2026-02-02', x2: '2026-02-10', y: 'Release' },
] }],
},
};
const picker = document.createElement('select');
for (const name of Object.keys(charts)) picker.add(new Option(name));
document.getElementById('app').before(picker);
let chart = null;
const show = (name) => {
chart?.destroy();
chart = VibeFoxJSCharts.createChart('#app', charts[name]);
};
picker.onchange = () => show(picker.value);
show(picker.value);Torta e altre serie senza assi
Scegliere un grafico nell'elenco: una ciambella con un indicatore, una torta (fare clic su una fetta per estrarla), radar, polare, barre radiali, un imbuto con una piramide, una treemap, un sunburst e grafici bullet.
const tree = [
{ name: 'Europe', children: [{ name: 'Germany', value: 84 }, { name: 'France', value: 68 }, { name: 'Italy', value: 59 }] },
{ name: 'Asia', children: [{ name: 'Japan', value: 124 }, { name: 'Korea', value: 52 }] },
{ name: 'Oceania', children: [{ name: 'Australia', value: 27 }, { name: 'New Zealand', value: 5 }] },
];
const charts = {
'Donut and gauge': { series: [
{ type: 'donut', name: 'Share', data: [{ name: 'Web', value: 55 }, { name: 'Store', value: 30 }, { name: 'Phone', value: 15 }],
showTotal: true, centerLabel: 'Orders' },
{ type: 'gauge', name: 'Load', data: [72], max: 100, bands: [{ from: 80, to: 100, color: '#dc2626' }] },
] },
'Pie': { series: [{ type: 'pie', name: 'Traffic', selectable: true, data: [
{ name: 'Direct', value: 24 }, { name: 'Search', value: 38 }, { name: 'Social', value: 18 }, { name: 'Email', value: 12 }, { name: 'Other', value: 8 },
] }] },
'Radar': {
categories: ['Speed', 'Quality', 'Price', 'Support', 'Design', 'Docs'],
series: [
{ name: 'Product A', type: 'radar', max: 100, data: [88, 92, 85, 78, 90, 70] },
{ name: 'Product B', type: 'radar', data: [80, 75, 90, 85, 70, 85] },
],
},
'Polar': {
categories: ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'],
series: [
{ name: 'Wind, days', type: 'polar', mode: 'column', data: [8, 5, 3, 4, 6, 9, 12, 10] },
{ name: 'Gusts', type: 'polar', mode: 'line', data: [4, 3, 2, 2, 3, 6, 8, 6] },
],
},
'Radial bars': { series: [{ type: 'radialBar', name: 'Goals', max: 100, rounded: true, data: [
{ name: 'Running', value: 82 }, { name: 'Swimming', value: 54 }, { name: 'Cycling', value: 67 },
] }] },
'Funnel and pyramid': { series: [
{ type: 'funnel', name: 'Sales funnel', data: [{ name: 'Visits', value: 1000 }, { name: 'Leads', value: 600 }, { name: 'Offers', value: 320 }, { name: 'Deals', value: 200 }] },
{ type: 'pyramid', name: 'Pyramid', data: [{ name: 'Base', value: 50 }, { name: 'Middle', value: 30 }, { name: 'Top', value: 10 }] },
] },
'Treemap': { series: [{ type: 'treemap', name: 'Population, M', data: tree }] },
'Sunburst': { series: [{ type: 'sunburst', name: 'Population, M', data: tree }] },
'Bullet': {
categories: ['Revenue', 'Profit', 'Orders'],
series: [{ type: 'bullet', name: 'KPI', data: [
{ y: 270, target: 250, ranges: [150, 225, 300] },
{ y: 180, target: 260, ranges: [150, 225, 300] },
{ y: 240, target: 230, ranges: [150, 225, 300] },
] }],
},
};
const picker = document.createElement('select');
for (const name of Object.keys(charts)) picker.add(new Option(name));
document.getElementById('app').before(picker);
let chart = null;
const show = (name) => {
chart?.destroy();
chart = VibeFoxJSCharts.createChart('#app', charts[name]);
};
picker.onchange = () => show(picker.value);
show(picker.value);Relazioni, testo e tempo
Scegliere un grafico nell'elenco: un diagramma sankey, un diagramma a corde, una ruota delle dipendenze, un diagramma ad arco, una rete (trascinare i suoi nodi), una nuvola di parole, un diagramma di Venn e una timeline.
const links = [['Coal', 'Power', 40], ['Gas', 'Power', 25], ['Solar', 'Power', 15], ['Power', 'Homes', 35], ['Power', 'Industry', 30], ['Power', 'Losses', 15], ['Gas', 'Homes', 10]];
const charts = {
'Sankey': { series: [{ type: 'sankey', name: 'Energy', data: links, linkColor: 'mix' }] },
'Chord': { series: [{ type: 'chord', name: 'Trade', nodes: ['Europe', 'Asia', 'America', 'Africa'],
matrix: [[0, 5, 4, 2], [6, 0, 5, 1], [3, 4, 0, 1], [2, 1, 1, 0]] }] },
'Dependency wheel': { series: [{ type: 'dependencyWheel', name: 'Modules',
data: [['core', 'ui', 5], ['core', 'data', 4], ['data', 'ui', 3], ['ui', 'app', 6], ['data', 'app', 2], ['auth', 'app', 2], ['core', 'auth', 2]] }] },
'Arc': { series: [{ type: 'arc', name: 'Calls', data: [['A', 'B', 3], ['A', 'D', 2], ['B', 'C', 1], ['C', 'E', 4], ['A', 'E', 1], ['D', 'F', 2], ['B', 'F', 3]] }] },
'Network': { series: [{ type: 'network', name: 'Team', draggable: true,
nodes: [{ id: 'Ann', group: 'Web' }, { id: 'Bob', group: 'Web' }, { id: 'Cid', group: 'Data' }, { id: 'Dan', group: 'Data' }, { id: 'Eve', group: 'Ops' }, { id: 'Fay', group: 'Ops' }],
data: [['Ann', 'Bob'], ['Ann', 'Cid'], ['Bob', 'Cid'], ['Cid', 'Dan'], ['Dan', 'Eve'], ['Eve', 'Fay'], ['Fay', 'Dan'], ['Ann', 'Eve']] }] },
'Word cloud': { series: [{ type: 'wordcloud', name: 'Words', data: [
['charts', 20], ['data', 16], ['canvas', 12], ['zoom', 10], ['legend', 9], ['tooltip', 9], ['export', 8], ['maps', 8],
['series', 7], ['axes', 7], ['themes', 6], ['labels', 6], ['drilldown', 5], ['dashboard', 5], ['realtime', 4], ['webgl', 4], ['pdf', 3], ['svg', 3],
] }] },
'Venn': { series: [{ type: 'venn', name: 'Skills', data: [
{ sets: ['JavaScript'], value: 10 }, { sets: ['Design'], value: 7 }, { sets: ['Data'], value: 6 },
{ sets: ['JavaScript', 'Design'], value: 3 }, { sets: ['JavaScript', 'Data'], value: 2 }, { sets: ['Design', 'Data'], value: 1.5 },
] }] },
'Timeline': { series: [{ type: 'timeline', name: 'Milestones', data: [
{ x: '2026-01-10', name: 'Start', description: 'Kick-off' }, { x: '2026-03-01', name: 'Beta', description: 'First users' },
{ x: '2026-05-20', name: 'Release', description: 'Version 1.0' }, { x: '2026-09-01', name: 'Update', description: 'Version 1.1' },
] }] },
};
const picker = document.createElement('select');
for (const name of Object.keys(charts)) picker.add(new Option(name));
document.getElementById('app').before(picker);
let chart = null;
const show = (name) => {
chart?.destroy();
chart = VibeFoxJSCharts.createChart('#app', charts[name]);
};
picker.onchange = () => show(picker.value);
show(picker.value);Assi
Un asse x temporale e due assi y: il prezzo a sinistra, il volume a destra con il proprio formato. Premere Log scale per passare l'asse sinistro a scala logaritmica e viceversa.
function addButton(text, onClick) {
const b = document.createElement('button');
b.textContent = text;
b.onclick = onClick;
document.getElementById('app').before(b);
}
const price = [10, 12, 11, 15, 18, 26, 31, 45, 52, 80, 95, 120];
const volume = [5000, 8000, 6500, 7000, 9000, 12000, 11000, 15000, 14000, 18000, 21000, 19000];
const month = (i) => '2026-' + String(i + 1).padStart(2, '0') + '-01';
const chart = VibeFoxJSCharts.createChart('#app', {
xAxis: { type: 'time' },
yAxis: [{ title: 'Price' }, { title: 'Volume', position: 'right', format: (v) => v / 1000 + 'k' }],
series: [
{ name: 'Price', markers: true, data: price.map((v, i) => [month(i), v]) },
{ name: 'Volume', type: 'column', yAxisIndex: 1, data: volume.map((v, i) => [month(i), v]) },
],
});
addButton('Log scale', () => chart.toggleLogScale(0));Etichette, tooltip, legenda e annotazioni
Etichette dei dati
Etichette con template posizionate fuori dalle colonne ed etichette percentuali delle fette della torta. Premere Labels on / off per attivare o disattivare le etichette delle colonne.
function addButton(text, onClick) {
const b = document.createElement('button');
b.textContent = text;
b.onclick = onClick;
document.getElementById('app').before(b);
}
const chart = VibeFoxJSCharts.createChart('#app', {
seriesLayout: 'row',
categories: ['North', 'South', 'East', 'West'],
series: [
{ name: 'Revenue', type: 'column', data: [42, 28, 35, 19],
dataLabels: { show: true, format: '{y} k', position: 'outside' } },
{ name: 'Share', type: 'pie', data: [{ name: 'North', value: 42 }, { name: 'South', value: 28 }, { name: 'East', value: 35 }, { name: 'West', value: 19 }],
dataLabels: { show: true, format: '{percent}' } },
],
});
addButton('Labels on / off', () => chart.toggleDataLabels());Tooltip e legenda
Un unico tooltip condiviso con un mirino e il proprio formato, la legenda a destra. Passare il mouse sull'area del grafico; passare il mouse su una voce della legenda per evidenziare la sua serie, fare clic per nascondere la serie.
VibeFoxJSCharts.createChart('#app', {
title: 'Website traffic',
subtitle: 'Thousands of visits per month',
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep'],
legend: { position: 'right' },
tooltip: {
shared: true,
crosshair: 'xy',
format: ({ title, rows }) => '<b>' + title + '</b><br>' + rows.map((r) => r.name + ': ' + r.value + ' k').join('<br>'),
},
series: [
{ name: 'Search', type: 'line', smooth: true, data: [32, 35, 38, 36, 42, 45, 44, 48, 52] },
{ name: 'Social', type: 'line', smooth: true, data: [18, 22, 21, 26, 25, 30, 33, 31, 36] },
{ name: 'Direct', type: 'line', smooth: true, data: [12, 12, 14, 13, 15, 16, 15, 17, 18] },
],
});Annotazioni e linee statistiche
Una linea obiettivo, una fascia ombreggiata della campagna, il minimo e il massimo evidenziati della serie del consuntivo, e le sue linee della media e del trend (stats).
const chart = VibeFoxJSCharts.createChart('#app', {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug'],
series: [
{ name: 'Plan', type: 'column', data: [10, 12, 9, 14, 15, 13, 16, 17] },
{ name: 'Fact', type: 'line', markers: true, data: [8, 14, 11, 13, 17, 16, 15, 19], stats: ['avg', 'trend'] },
],
});
chart.addAnnotation({ id: 'goal', type: 'lineY', value: 15, text: 'Goal', dash: [4, 4] });
chart.addAnnotation({ type: 'rangeX', from: 'Mar', to: 'Apr', text: 'Campaign', opacity: 0.15 });
chart.annotateExtremes(1);Confronto fantasma
Il contorno tratteggiato è la settimana scorsa, conservata con snapshot() prima che fossero impostati i nuovi dati. Premere Next week per confrontare di nuovo.
function addButton(text, onClick) {
const b = document.createElement('button');
b.textContent = text;
b.onclick = onClick;
document.getElementById('app').before(b);
}
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
const weeks = [[42, 48, 51, 47, 55, 38, 30], [45, 52, 49, 53, 60, 41, 33], [40, 44, 47, 50, 52, 45, 39], [48, 55, 58, 54, 63, 47, 36]];
let week = 0;
const series = (w) => [{ id: 'visits', name: 'Visits, k', type: 'column', data: weeks[w] }];
const chart = VibeFoxJSCharts.createChart('#app', { categories: days, series: series(0) });
const next = () => {
week = (week + 1) % weeks.length;
chart.snapshot();
chart.setData(series(week));
};
addButton('Next week', next);
next();Zoom, navigatore e selettore dell'intervallo
Due anni di valori giornalieri con i pulsanti del selettore dell'intervallo e le date in alto, il navigatore e la barra di scorrimento in basso. Premere un pulsante dell'intervallo, trascinare la finestra nel navigatore oppure trascinare sull'area del grafico per lo zoom.
const start = Date.UTC(2025, 0, 1);
const day = 24 * 3600 * 1000;
const data = Array.from({ length: 730 }, (_, i) =>
[start + i * day, Math.round(200 + i * 0.4 + Math.sin(i / 15) * 40 + Math.sin(i / 3) * 12)]);
const chart = VibeFoxJSCharts.createChart('#app', {
xAxis: { type: 'time' },
series: [{ name: 'Active users', type: 'area', fillOpacity: 0.2, data }],
navigator: { enabled: true },
scrollbar: { enabled: true },
rangeSelector: { enabled: true, selected: '6M' },
});Drilldown
Fare clic su Europe: i suoi paesi si aprono da drilldown.series. Fare clic su America: il livello viene caricato da drilldown.load (qui una funzione di prova (stub) con un breve ritardo al posto di un server). Le breadcrumb riportano indietro.
VibeFoxJSCharts.createChart('#app', {
series: [{ id: 'regions', type: 'column', name: 'Regions',
data: [{ name: 'Europe', y: 30, drilldown: 'eu' }, { name: 'America', y: 20, drilldown: true }] }],
drilldown: {
series: [{ id: 'eu', type: 'column', name: 'Europe', data: [{ name: 'Germany', y: 12 }, { name: 'France', y: 18 }] }],
load: async (ctx) => {
await new Promise((resolve) => setTimeout(resolve, 300)); // your server request here
return { type: 'pie', name: ctx.point.name, data: [{ name: 'USA', value: 15 }, { name: 'Canada', value: 5 }] };
},
},
});Dati in tempo reale
Un nuovo punto ogni mezzo secondo; la finestra conserva gli ultimi 120 punti (realtime.maxPoints).
let t = Date.now() - 60 * 500;
let v = 50;
const next = () => {
t += 500;
v = Math.max(5, Math.min(95, v + (Math.random() - 0.5) * 12));
return [t, Math.round(v)];
};
const chart = VibeFoxJSCharts.createChart('#app', {
xAxis: { type: 'time' },
realtime: { maxPoints: 120 },
series: [{ id: 'cpu', name: 'CPU, %', type: 'area', fillOpacity: 0.25, data: Array.from({ length: 60 }, next) }],
});
setInterval(() => chart.appendData('cpu', [next()]), 500);Fonti dei dati
Il grafico legge la tabella HTML sopra di esso (dataSource.table con watch: true). Fare clic su un numero della tabella e cambiarlo: il grafico lo segue.
const table = document.createElement('table');
table.id = 'sales';
table.contentEditable = 'true';
table.innerHTML = '<thead><tr><th>Month</th><th>North</th><th>South</th></tr></thead><tbody>'
+ '<tr><td>Jan</td><td>5</td><td>3</td></tr><tr><td>Feb</td><td>6</td><td>4</td></tr>'
+ '<tr><td>Mar</td><td>7</td><td>2</td></tr><tr><td>Apr</td><td>8</td><td>5</td></tr></tbody>';
document.getElementById('app').before(table);
VibeFoxJSCharts.createChart('#app', {
dataSource: { table: '#sales', watch: true, type: 'column', x: 'Month', y: ['North', 'South'] },
});Grandi dati
Una linea di 200.000 punti disegnata tramite WebGL (largeData.webgl) e sottocampionata alla finestra visibile; la riga sotto il grafico è getRenderInfo(). Ingrandire con la rotella: compaiono più dettagli. La libreria gestisce milioni di punti; la demo mantiene la pagina leggera.
const output = document.createElement('p');
document.getElementById('app').after(output);
const points = Array.from({ length: 200000 }, (_, i) =>
[i, Math.sin(i / 5000) * 100 + Math.sin(i / 300) * 20 + ((i * 7919) % 100) / 10]);
const chart = VibeFoxJSCharts.createChart('#app', {
series: [{ name: 'Signal', type: 'line', data: points }],
largeData: { webgl: true },
});
const info = () => {
const r = chart.getRenderInfo()[0];
output.textContent = r.points + ' points, ' + r.drawn + ' drawn, method ' + r.method + ', renderer ' + r.renderer;
};
chart.on('zoomChange', info);
info();Modifica dei punti
Trascinare una colonna verso l'alto o verso il basso (passi di 0,5 tra 0 e 10), oppure dare il focus al grafico e usare Shift+tasti freccia. Undo e Redo (oppure Ctrl+Z / Ctrl+Y) scorrono tra gli spostamenti.
function addButton(text, onClick) {
const b = document.createElement('button');
b.textContent = text;
b.onclick = onClick;
document.getElementById('app').before(b);
}
const output = document.createElement('p');
document.getElementById('app').after(output);
const chart = VibeFoxJSCharts.createChart('#app', {
categories: ['A', 'B', 'C', 'D', 'E'],
yAxis: { min: 0, max: 10 },
series: [{ name: 'Budget', type: 'column', data: [5, 7, 3, 6, 4], draggable: { min: 0, max: 10, step: 0.5 } }],
});
chart.on('pointDrop', (e) => { output.textContent = 'New value of ' + chart.getOption('categories')[e.index] + ': ' + e.value.y; });
addButton('Undo', () => chart.undo());
addButton('Redo', () => chart.redo());Mappe
Una mappa coropletica di un piccolo paese fittizio (il suo GeoJSON è nel codice), con le capitali come punti e un percorso. Passare il mouse su una regione, scorrere per lo zoom, trascinare per lo spostamento, fare doppio clic per reimpostare; Zoom to North chiama zoomToRegion().
function addButton(text, onClick) {
const b = document.createElement('button');
b.textContent = text;
b.onclick = onClick;
document.getElementById('app').before(b);
}
// your GeoJSON (here: six made-up regions); TopoJSON works too
const T = [[0, 52], [4.2, 52.6], [8.1, 52.3], [12, 51.6]];
const M = [[-0.4, 48.2], [4.6, 47.7], [7.6, 48.5], [12.5, 48]];
const B = [[0.3, 44], [4, 43.6], [8.4, 44.2], [11.6, 44.5]];
const region = (id, name, low, high, i) => ({ type: 'Feature', id, properties: { name },
geometry: { type: 'Polygon', coordinates: [[low[i], low[i + 1], high[i + 1], high[i], low[i]]] } });
const geo = { type: 'FeatureCollection', features: [
region('NW', 'Northwest', M, T, 0), region('N', 'North', M, T, 1), region('NE', 'Northeast', M, T, 2),
region('SW', 'Southwest', B, M, 0), region('S', 'South', B, M, 1), region('SE', 'Southeast', B, M, 2),
] };
const chart = VibeFoxJSCharts.createChart('#app', {
map: { data: geo },
colorAxis: { type: 'sequential', steps: 5, title: 'Population (M)' },
series: [
{ type: 'map', name: 'Population', joinBy: 'id', data: [
{ id: 'NW', value: 4.2 }, { id: 'N', value: 9.8 }, { id: 'NE', value: 6.1 },
{ id: 'SW', value: 2.4 }, { id: 'S', value: 7.3 }, { id: 'SE', value: 3.5 },
] },
{ type: 'mappoint', name: 'Cities', data: [
{ name: 'Northport', lon: 6.2, lat: 50.4 }, { name: 'Southfield', lon: 6, lat: 46 }, { name: 'Eastbay', lon: 10.5, lat: 49.5 },
] },
{ type: 'mapline', name: 'Route', data: [{ from: [6.2, 50.4], to: [10.5, 49.5] }, { from: [6.2, 50.4], to: [6, 46] }] },
],
});
addButton('Zoom to North', () => chart.zoomToRegion(0, 'N'));
addButton('Reset', () => chart.resetMapView());Regole responsive
Spostare il cursore per cambiare la larghezza del grafico: sotto i 500 px la legenda passa in basso, le etichette dell'asse x ruotano e le etichette dei dati sono nascoste.
const output = document.createElement('p');
document.getElementById('app').after(output);
const app = document.getElementById('app');
const slider = document.createElement('input');
slider.type = 'range'; slider.min = 300; slider.max = 900; slider.value = 900;
app.before(slider);
const chart = VibeFoxJSCharts.createChart('#app', {
categories: ['January', 'February', 'March', 'April', 'May', 'June'],
legend: { position: 'right' },
dataLabels: true,
series: [
{ name: 'Laptops', type: 'column', data: [12, 15, 11, 18, 21, 19] },
{ name: 'Phones', type: 'column', data: [22, 19, 24, 27, 25, 30] },
],
responsive: { rules: [
{ condition: { maxWidth: 500 }, options: { legend: { position: 'bottom' }, xAxis: { labelRotation: 45 }, dataLabels: false } },
] },
});
chart.on('responsiveChange', (e) => { output.textContent = 'Width ' + Math.round(e.width) + ' px, rules active: ' + e.active.length; });
slider.oninput = () => { app.style.maxWidth = slider.value + 'px'; };Dashboard
Riquadri KPI, due grafici e due filtri da un'unica configurazione. Fare clic su una fetta della torta: il grafico a colonne e i KPI mostrano solo quella regione (filtro incrociato); cambiare il filtro del prodotto.
const regions = ['North', 'South', 'East', 'West'];
const products = ['Laptops', 'Phones', 'Tablets'];
const data = [];
for (let m = 1; m <= 12; m++) {
for (let r = 0; r < regions.length; r++) {
for (let p = 0; p < products.length; p++) {
data.push({ date: '2026-' + String(m).padStart(2, '0') + '-15', region: regions[r], product: products[p],
amount: 50 + ((m * 37 + r * 53 + p * 71) % 90) + m * 4 });
}
}
}
const dash = VibeFoxJSCharts.createChartDashboard('#app', {
title: 'Sales 2026',
data,
kpis: [
{ id: 'total', title: 'Revenue', field: 'amount', aggregate: 'sum', format: { compact: true }, sparkline: { field: 'date', by: 'month' } },
{ id: 'avg', title: 'Average order', field: 'amount', aggregate: 'avg' },
{ id: 'count', title: 'Orders', field: 'amount', aggregate: 'count' },
],
charts: [
{ id: 'byRegion', title: 'By region', type: 'pie', x: 'region', y: 'amount', aggregate: 'sum' },
{ id: 'byMonth', title: 'By month', type: 'column', x: { field: 'date', by: 'month' }, y: 'amount', series: 'product', stacked: true },
],
filters: [
{ id: 'product', field: 'product', type: 'multiselect' },
{ id: 'region', field: 'region', type: 'select' },
],
layout: { breakpoints: { 0: 6 } }, // six columns at every width
});Esportazione
I pulsanti scaricano il grafico come file PNG, SVG (vettoriali), PDF (vettoriali), CSV ed Excel, aprono la finestra di stampa oppure mostrano i dati come tabella accessibile.
function addButton(text, onClick) {
const b = document.createElement('button');
b.textContent = text;
b.onclick = onClick;
document.getElementById('app').before(b);
}
const chart = VibeFoxJSCharts.createChart('#app', {
title: 'Sales 2026',
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
series: [
{ name: 'Plan', type: 'column', data: [10, 12, 9, 14, 15, 13] },
{ name: 'Fact', type: 'line', markers: true, data: [8, 14, 11, 13, 17, 16] },
],
});
addButton('PNG', () => chart.exportPNG('sales.png'));
addButton('SVG', () => chart.exportSVG('sales.svg'));
addButton('PDF', () => chart.exportPDF('sales.pdf', { pageSize: 'A4', orientation: 'landscape' }));
addButton('CSV', () => chart.exportCSV('sales.csv'));
addButton('Excel', () => chart.exportXLSX('sales.xlsx', { sheets: 'series' }));
addButton('Print', () => chart.print());
addButton('Data table', () => chart.toggleDataView());Rendering senza DOM
Qui non c'è un componente grafico: renderToSVG() ha restituito una stringa SVG (mostrata come immagine); la stessa chiamata funziona in Node o in un worker. Premere New data per renderizzarlo di nuovo.
function addButton(text, onClick) {
const b = document.createElement('button');
b.textContent = text;
b.onclick = onClick;
document.getElementById('app').before(b);
}
const img = document.createElement('img');
img.alt = 'Rendered chart';
document.getElementById('app').append(img);
let n = 0;
const render = () => {
n++;
const svg = VibeFoxJSCharts.renderToSVG({
title: 'Report ' + n,
categories: ['A', 'B', 'C', 'D', 'E'],
series: [{ name: 'Value', type: 'column', data: [3, 5, 2, 6, 4].map((v, i) => v + ((n * (i + 2)) % 4)) }],
}, { width: 600, height: 300, theme: 'light' });
img.src = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg);
};
addButton('New data', render);
render();Da testo a grafico e spiegazioni
Digitare una richiesta (oppure sceglierne una) e premere Make chart: textToChart() costruisce le opzioni con regole integrate, senza bisogno di un modello. Il testo sotto il grafico è explain().
const output = document.createElement('p');
document.getElementById('app').after(output);
const rows = [
{ month: 'Jan', region: 'North', product: 'Laptops', sales: 120 }, { month: 'Jan', region: 'South', product: 'Phones', sales: 80 },
{ month: 'Feb', region: 'North', product: 'Phones', sales: 150 }, { month: 'Feb', region: 'East', product: 'Tablets', sales: 60 },
{ month: 'Mar', region: 'South', product: 'Laptops', sales: 170 }, { month: 'Mar', region: 'West', product: 'Phones', sales: 90 },
{ month: 'Apr', region: 'East', product: 'Laptops', sales: 140 }, { month: 'Apr', region: 'West', product: 'Tablets', sales: 75 },
{ month: 'May', region: 'North', product: 'Tablets', sales: 110 }, { month: 'May', region: 'South', product: 'Phones', sales: 130 },
];
const input = document.createElement('input');
input.size = 40;
input.value = 'sales by region as pie';
input.setAttribute('list', 'requests');
const list = document.createElement('datalist');
list.id = 'requests';
for (const r of ['sales by region as pie', 'sales by month as line', 'sales by product as bar', 'sales by month and region stacked column']) list.append(new Option(r));
const button = document.createElement('button');
button.textContent = 'Make chart';
document.getElementById('app').before(input, list, button);
let chart = null;
const make = () => {
chart?.destroy();
chart = VibeFoxJSCharts.createChart('#app', VibeFoxJSCharts.textToChart(input.value, rows));
output.textContent = chart.explain();
};
button.onclick = make;
make();Temi e stile
Temi
Scegliere un tema nell'elenco: chiaro, scuro, ad alto contrasto e i temi del pacchetto vibefox-js-themes.css (ocean, sunset, glass-dark, paper, graphite-dark).
const chart = VibeFoxJSCharts.createChart('#app', {
title: 'Sales 2026',
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
series: [
{ name: 'Plan', type: 'column', data: [10, 12, 9, 14, 15, 13] },
{ name: 'Fact', type: 'line', markers: true, data: [8, 14, 11, 13, 17, 16] },
{ name: 'Last year', type: 'line', dash: [6, 4], data: [7, 9, 10, 11, 12, 12] },
],
});
const picker = document.createElement('select');
for (const name of ['light', 'dark', 'high-contrast', 'ocean', 'sunset', 'glass-dark', 'paper', 'graphite-dark']) picker.add(new Option(name));
picker.onchange = () => chart.setTheme(picker.value);
document.getElementById('app').before(picker);Variabili CSS
Vengono modificate solo le variabili CSS di questo grafico: i colori di accento e delle serie, un carattere più grande, linee della griglia tratteggiate e colonne con angoli arrotondati.
const app = document.getElementById('app');
app.style.cssText = '--vfjs-charts-font-size: 14px; --vfjs-charts-grid-dash: 4 3; --vfjs-charts-bar-radius: 6px;'
+ '--vfjs-charts-color-0: #0f766e; --vfjs-charts-color-1: #f59e0b; --vfjs-charts-title-fg: #0f766e;';
VibeFoxJSCharts.createChart('#app', {
title: 'Styled with CSS variables',
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
series: [
{ name: 'Plan', type: 'column', data: [10, 12, 9, 14, 15, 13] },
{ name: 'Fact', type: 'line', markers: true, data: [8, 14, 11, 13, 17, 16] },
],
});Stili pronti all'uso e palette
Scegliere uno stile pronto (vivace, pastello, monocromatico, scuro, stampa) e una palette (anche quelle adatte al daltonismo). Stampa e monocromatico usano retinature, tratteggi e forme dei marcatori.
const chart = VibeFoxJSCharts.createChart('#app', {
categories: ['Q1', 'Q2', 'Q3', 'Q4'],
series: [
{ name: 'North', type: 'column', data: [5, 6, 7, 8] },
{ name: 'South', type: 'column', data: [3, 4, 2, 5] },
{ name: 'East', type: 'column', data: [4, 5, 6, 4] },
{ name: 'Target', type: 'line', markers: true, data: [6, 7, 8, 9] },
{ name: 'Last year', type: 'line', markers: true, data: [4, 4, 5, 6] },
],
});
const style = document.createElement('select');
const palette = document.createElement('select');
style.add(new Option('style: default', ''));
for (const name of VibeFoxJSCharts.CHART_STYLES) style.add(new Option('style: ' + name, name));
palette.add(new Option('palette: default', ''));
for (const name of VibeFoxJSCharts.CHART_PALETTES) palette.add(new Option('palette: ' + name, name));
style.onchange = () => chart.setStyle(style.value || null);
palette.onchange = () => chart.setPalette(palette.value || null);
document.getElementById('app').before(style, palette);Densità e dimensione
Scegliere una densità per il contenitore (data-vfjs-density) e un'unità di dimensione (--vfjs-size-unit): testi, spaziature interne e marcatori si adeguano.
const app = document.getElementById('app');
app.style.height = '400px';
const chart = VibeFoxJSCharts.createChart('#app', {
title: 'Density',
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
series: [
{ name: 'Plan', type: 'column', data: [10, 12, 9, 14, 15, 13] },
{ name: 'Fact', type: 'line', markers: true, data: [8, 14, 11, 13, 17, 16] },
],
});
const density = document.createElement('select');
for (const name of ['normal', 'compact', 'comfortable']) density.add(new Option('density: ' + name, name));
density.onchange = () => { app.dataset.vfjsDensity = density.value; };
const unit = document.createElement('select');
for (const px of ['1px', '0.8px', '1.25px']) unit.add(new Option('--vfjs-size-unit: ' + px, px));
unit.onchange = () => app.style.setProperty('--vfjs-size-unit', unit.value);
app.before(density, unit);Il proprio CSS
Regole CSS semplici della pagina modificano la legenda e il titolo; prevalgono sulla libreria senza !important, perché il CSS della libreria si trova in @layer vfjs.
const css = document.createElement('style');
css.textContent = '.vfjs-chart-legend-item { font-weight: 600; text-transform: uppercase; }'
+ ' .vfjs-chart-header { text-align: start; border-bottom: 2px solid #0f766e; }';
document.head.append(css);
VibeFoxJSCharts.createChart('#app', {
title: 'My styled chart',
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
series: [
{ name: 'Plan', type: 'column', data: [10, 12, 9, 14, 15, 13] },
{ name: 'Fact', type: 'line', markers: true, data: [8, 14, 11, 13, 17, 16] },
],
});Localizzazione e RTL
Lingue
Cambiare la lingua tra inglese e russo (il pacchetto linguistico vibefox-js-charts.ru.js viene caricato dopo la libreria): il selettore dell'intervallo, le linee statistiche, i nomi dei mesi dell'asse temporale e il formato dei numeri si adeguano.
const start = Date.UTC(2025, 0, 1);
const day = 24 * 3600 * 1000;
const chart = VibeFoxJSCharts.createChart('#app', {
locale: 'en',
xAxis: { type: 'time' },
rangeSelector: { enabled: true, selected: '6M' },
series: [{ name: 'Orders', type: 'line', stats: ['avg', 'min', 'max'],
data: Array.from({ length: 365 }, (_, i) => [start + i * day, Math.round(12000 + Math.sin(i / 20) * 3000 + i * 10)]) }],
});
const picker = document.createElement('select');
picker.add(new Option('English', 'en'));
picker.add(new Option('Русский', 'ru'));
picker.onchange = () => chart.setOptions({ locale: picker.value });
document.getElementById('app').before(picker);Aggiunta di una lingua
Un dizionario tedesco parziale aggiunto con addLocale(): il selettore dell'intervallo e le linee statistiche lo usano, i nomi dei mesi provengono dal browser, il resto ricade sull'inglese.
VibeFoxJSCharts.addLocale('de', {
chartRangeAll: 'Alle',
chartRangeAllTitle: 'Alle Daten',
chartRangeFrom: 'Von',
chartRangeTo: 'Bis',
chartRangeShortM: 'M',
chartRangeShortY: 'J',
chartStatAvg: 'Durchschnitt',
chartStatMin: 'Minimum',
chartStatMax: 'Maximum',
});
const start = Date.UTC(2025, 0, 1);
const day = 24 * 3600 * 1000;
VibeFoxJSCharts.createChart('#app', {
locale: 'de',
xAxis: { type: 'time' },
rangeSelector: { enabled: true, selected: '6M' },
series: [{ name: 'Bestellungen', type: 'line', stats: ['avg', 'min', 'max'],
data: Array.from({ length: 365 }, (_, i) => [start + i * day, Math.round(12000 + Math.sin(i / 20) * 3000 + i * 10)]) }],
});Da destra a sinistra
L'opzione rtl: true: il titolo, la legenda e il tooltip seguono la direzione da destra a sinistra; l'area del grafico mantiene l'asse x crescente verso destra.
VibeFoxJSCharts.createChart('#app', {
rtl: true,
title: 'المبيعات',
subtitle: 'Sales by quarter',
categories: ['Q1', 'Q2', 'Q3', 'Q4'],
series: [
{ name: 'الشمال', type: 'column', data: [5, 6, 7, 8] },
{ name: 'الجنوب', type: 'column', data: [3, 4, 2, 5] },
],
});Accessibilità
Tastiera
Il terzo punto riceve il focus dal codice (focusPoint()). Fare clic sul grafico (oppure spostarsi su di esso con Tab) e usare i tasti freccia, Home / End, + / − per lo zoom, Enter per fare clic su un punto.
const chart = VibeFoxJSCharts.createChart('#app', {
title: 'Use the keyboard',
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug'],
series: [
{ name: 'Visitors', type: 'line', markers: true, data: [42, 45, 51, 49, 58, 63, 61, 67] },
{ name: 'Orders', type: 'line', markers: true, data: [12, 14, 13, 17, 19, 18, 22, 24] },
],
});
chart.focusPoint(0, 2, { focus: false });Screen reader
Il testo sotto il grafico è getSummary(), la descrizione che ricevono gli screen reader. Speak summary lo annuncia a uno screen reader; Data table mostra i dati come tabella HTML accessibile.
function addButton(text, onClick) {
const b = document.createElement('button');
b.textContent = text;
b.onclick = onClick;
document.getElementById('app').before(b);
}
const output = document.createElement('p');
document.getElementById('app').after(output);
const chart = VibeFoxJSCharts.createChart('#app', {
title: 'Revenue and costs',
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
series: [
{ name: 'Revenue', type: 'column', data: [120, 135, 128, 150, 162, 171] },
{ name: 'Costs', type: 'line', markers: true, data: [90, 95, 99, 101, 108, 110] },
],
});
output.textContent = chart.getSummary();
addButton('Speak summary', () => chart.announceSummary());
addButton('Data table', () => chart.toggleDataView());Uso con altre librerie VibeFox JS
Collegamento dei componenti con link()
Due grafici collegati con link(): eseguire lo zoom sul grafico superiore (trascinando sulla sua area o usando il suo navigatore) e il grafico inferiore mostra lo stesso intervallo.
const app = document.getElementById('app');
const upper = document.createElement('div');
const lower = document.createElement('div');
upper.style.height = '260px';
lower.style.height = '200px';
app.append(upper, lower);
const start = Date.UTC(2026, 0, 1);
const day = 24 * 3600 * 1000;
const days = Array.from({ length: 180 }, (_, i) => start + i * day);
const overview = VibeFoxJSCharts.createChart(upper, {
title: 'Price', xAxis: { type: 'time' }, navigator: { enabled: true },
series: [{ name: 'Price', type: 'line', data: days.map((t, i) => [t, Math.round(100 + i * 0.3 + Math.sin(i / 9) * 12)]) }],
});
const detail = VibeFoxJSCharts.createChart(lower, {
title: 'Volume', xAxis: { type: 'time' }, zoom: { enabled: false },
series: [{ name: 'Volume', type: 'column', data: days.map((t, i) => [t, 500 + ((i * 7919) % 400)]) }],
});
VibeFoxJSCharts.link(overview, 'zoomChange', detail, 'setXRange');
overview.setZoom(0.5, 0.8);Strumenti AI
Digitare una richiesta come "show as bar", "pie" o "title Revenue 2026" e premere Ask. La funzione model qui è un piccolo stub che risponde con una chiamata di strumento; nella propria applicazione la invia al proprio modello. Il log mostra le chiamate di strumento.
const output = document.createElement('p');
document.getElementById('app').after(output);
const chart = VibeFoxJSCharts.createChart('#app', {
title: 'Sales',
categories: ['North', 'South', 'East', 'West'],
series: [{ name: 'Sales', type: 'column', data: [42, 28, 35, 19] }],
});
const kit = VibeFoxJSCharts.createToolKit({ sales: chart });
// stub of your model: reads the last user message and answers with a tool call or a text
async function model(request) {
const last = request.messages[request.messages.length - 1];
if (last.role === 'tool') return { text: 'Done.' };
const text = last.content.toLowerCase();
const type = ['bar', 'pie', 'line', 'area', 'column', 'donut'].find((t) => text.includes(t));
const title = text.startsWith('title ') ? last.content.slice(6) : null;
if (title) return { toolCalls: [{ name: 'sales_chart_set_options', arguments: { title } }] };
if (type) {
const values = [42, 28, 35, 19];
const data = type === 'pie' || type === 'donut' ? ['North', 'South', 'East', 'West'].map((name, i) => ({ name, value: values[i] })) : values;
return { toolCalls: [{ name: 'sales_chart_set_options', arguments: { series: [{ name: 'Sales', type, data }] } }] };
}
return { toolCalls: [{ name: 'sales_chart_explain', arguments: {} }] };
}
const input = document.createElement('input');
input.size = 30;
input.value = 'show as bar';
const button = document.createElement('button');
button.textContent = 'Ask';
document.getElementById('app').before(input, button);
output.textContent = 'Tools: ' + kit.describe().map((t) => t.name).join(', ');
button.onclick = async () => {
const answer = await kit.ask(input.value, { model });
output.textContent = answer.calls.map((c) => c.name + ' ' + JSON.stringify(c.args) + ' → ' + JSON.stringify(c.result)).join('; ') || answer.text;
};