Personalización

Personaliza la gráfica con los puertos de contenido del renderer Web. El texto también se usa en servidor, accesibilidad y exportación.

Prueba la personalización

Cambia los formatos y explora la gráfica para ver los cinco puntos de personalización en uso. El código debajo se actualiza con los ajustes aplicados.

Configura un gráfico real. El código inferior muestra los datos y opciones de entrada, incluidas las reglas responsive.

Media actual: 4081,82 EUR

Ingresos por periodo · personalizado-10 mil EUR-10 mil EUR-5 mil EUR-5 mil EUR0 EUR0 EUR5 mil EUR5 mil EUR10 mil EUR10 mil EURPeriodo 1Periodo 1Periodo 2Periodo 2Periodo 3Periodo 3Periodo 4Periodo 4Periodo 5Periodo 5Periodo 6Periodo 64,2 mil EUR4,2 mil EUR5,3 mil EUR5,3 mil EUR6,8 mil EUR6,8 mil EUR4,8 mil EUR4,8 mil EUR-5,1 mil EUR-5,1 mil EUR5,9 mil EUR5,9 mil EURMedia: 4081,82 EURMedia: 4081,82 EUR

Ingresos por periodo · personalizado

Datos originales
SerieCategoría XidxyVisible
Serie 1Periodo 1series-0-0period-04200Sí
Serie 1Periodo 2series-0-1period-16100Sí
Serie 1Periodo 3series-0-2period-25300Sí
Serie 1Periodo 4series-0-3period-3Medición ausenteSí
Serie 1Periodo 5series-0-4period-47200Sí
Serie 1Periodo 6series-0-5period-56800Sí
Serie 2Periodo 1series-1-0period-03300Sí
Serie 2Periodo 2series-1-1period-14800Sí
Serie 2Periodo 3series-1-2period-20Sí
Serie 2Periodo 4series-1-3period-3-5100Sí
Serie 2Periodo 5series-1-4period-46400Sí
Serie 2Periodo 6series-1-5period-55900Sí

Último punto seleccionado: —

La media incluye cada valor válido de las series elegidas, también cero; omite los ausentes. En modo visible se recalcula al ocultar series. Se actualiza con los datos y no cambia con el zoom. Un objetivo fuera del dominio no se dibuja. Cambiar moneda o unidad formatea el valor: no hace conversiones.

data + options
const data = {
  "type": "column",
  "axes": {
    "x": {
      "type": "category",
      "values": [
        {
          "id": "period-0",
          "label": "Periodo 1"
        },
        {
          "id": "period-1",
          "label": "Periodo 2"
        },
        {
          "id": "period-2",
          "label": "Periodo 3"
        },
        {
          "id": "period-3",
          "label": "Periodo 4"
        },
        {
          "id": "period-4",
          "label": "Periodo 5"
        },
        {
          "id": "period-5",
          "label": "Periodo 6"
        }
      ]
    },
    "y": {
      "type": "linear"
    }
  },
  "series": [
    {
      "id": "series-0",
      "name": "Serie 1",
      "data": [
        {
          "id": "series-0-0",
          "x": "period-0",
          "y": 4200
        },
        {
          "id": "series-0-1",
          "x": "period-1",
          "y": 6100
        },
        {
          "id": "series-0-2",
          "x": "period-2",
          "y": 5300
        },
        {
          "id": "series-0-3",
          "x": "period-3",
          "y": null
        },
        {
          "id": "series-0-4",
          "x": "period-4",
          "y": 7200
        },
        {
          "id": "series-0-5",
          "x": "period-5",
          "y": 6800
        }
      ]
    },
    {
      "id": "series-1",
      "name": "Serie 2",
      "data": [
        {
          "id": "series-1-0",
          "x": "period-0",
          "y": 3300
        },
        {
          "id": "series-1-1",
          "x": "period-1",
          "y": 4800
        },
        {
          "id": "series-1-2",
          "x": "period-2",
          "y": 0
        },
        {
          "id": "series-1-3",
          "x": "period-3",
          "y": -5100
        },
        {
          "id": "series-1-4",
          "x": "period-4",
          "y": 6400
        },
        {
          "id": "series-1-5",
          "x": "period-5",
          "y": 5900
        }
      ]
    }
  ]
};

const options = {
  "title": "Ingresos por periodo",
  "locale": "es",
  "theme": "light",
  "height": 380,
  "animation": {
    "enabled": false
  },
  "formatting": {
    "locale": "es-ES",
    "number": {
      "minimumFractionDigits": 2,
      "maximumFractionDigits": 2,
      "style": "currency",
      "currency": "EUR",
      "currencyDisplay": "code",
      "currencySign": "standard"
    }
  },
  "appearance": {
    "colors": [
      "#2c6ed5",
      "#698e37"
    ],
    "markers": true,
    "dataLabels": true,
    "labelLimit": 8
  },
  "hiddenSeriesIds": [],
  "legend": {
    "position": "bottom"
  },
  "tooltip": {
    "crosshair": true,
    "content": "shared"
  },
  "references": [
    {
      "id": "comparison",
      "axis": "y",
      "value": 4081.818181818182
    }
  ],
  "referenceLabels": [
    {
      "id": "comparison",
      "text": "Media: 4081,82 EUR"
    }
  ],
  "referenceStyles": [
    {
      "id": "comparison",
      "color": "#875310",
      "dash": "dashed",
      "width": 1.5
    }
  ],
  "responsive": [
    {
      "maxWidth": 430,
      "options": {
        "height": 320,
        "tooltip": {
          "placement": "docked"
        },
        "appearance": {
          "dataLabels": false
        },
        "axes": {
          "y": {
            "numberFormat": {
              "minimumFractionDigits": 0,
              "maximumFractionDigits": 0,
              "style": "currency",
              "currency": "EUR",
              "currencyDisplay": "narrowSymbol",
              "currencySign": "standard",
              "notation": "compact"
            }
          }
        }
      }
    }
  ]
};

Copia el archivo completo para reproducir los datos, opciones y personalización que ves ahora. Elige Líneas en esta página para probar un eje de fechas UTC.

custom-chart.ts
import {createChart, type ChartData} from '@neural-charts/web';
import {ChartContentSlotName, type ChartContentPorts, type ChartOptions} from '@neural-charts/web';

export function createContent(options: ChartOptions, timeAxis: boolean, browserTemplates = false): ChartContentPorts {
  const region = options.formatting?.locale ?? options.locale ?? 'en';
  const numberOptions = options.formatting?.number;
  const number = new Intl.NumberFormat(region, numberOptions);
  const compact = new Intl.NumberFormat(region, {
    ...numberOptions,
    notation: 'compact',
    minimumFractionDigits: 0,
    maximumFractionDigits: 1,
  });
  const date = new Intl.DateTimeFormat(region, {day: 'numeric', month: 'short', timeZone: 'UTC'});

  const text = {
    [ChartContentSlotName.Title]: {text: context => context.defaultText + (context.locale === 'es' ? ' · personalizado' : ' · custom')},
    [ChartContentSlotName.Tooltip]: {text: context => {
      const value = context.observation.xValue;
      const heading = timeAxis && value !== undefined ? date.format(value) : context.observation.label;
      const title = context.locale === 'es' ? 'Detalle personalizado' : 'Custom detail';
      const missing = context.locale === 'es' ? 'Medición ausente' : 'Missing measurement';
      const rows = context.rows?.map(row => row.name + ': ' + (row.point ? number.format(row.point.value) : missing))
        ?? context.points.map(point => point.seriesName + ': ' + number.format(point.value));
      return [title + ' · ' + heading, ...rows].join('\n');
    }},
    [ChartContentSlotName.Legend]: {text: context => context.name + (context.visible ? '' : context.locale === 'es' ? ' · oculta' : ' · hidden')},
    [ChartContentSlotName.AxisLabel]: {text: context => {
      const {tick, axis, defaultText} = context;
      if (typeof tick.value !== 'number') return defaultText;
      if (axis === 'x' && tick.type === 'time') return date.format(tick.value);
      if (axis === 'y' && tick.type === 'number') return compact.format(tick.value);
      return defaultText;
    }},
    [ChartContentSlotName.DataLabel]: {text: context => {
      const value = context.observation?.value;
      if (value === undefined) return context.defaultText;
      const label = compact.format(value);
      return options.appearance?.points ? (context.index + 1) + ' · ' + label : label;
    }},
  } satisfies ChartContentPorts;

  if (!browserTemplates) return text;
  const html = (tag: 'strong' | 'em', attribute: string) => (host: HTMLElement, context: {readonly text: string}) => {
    const node = host.ownerDocument.createElement(tag);
    node.setAttribute(attribute, '');
    node.textContent = context.text;
    host.append(node);
    return () => node.remove();
  };
  const svg = (attribute: string) => (host: SVGTextElement, context: {readonly text: string}) => {
    const node = host.ownerDocument.createElementNS('http://www.w3.org/2000/svg', 'tspan');
    node.setAttribute(attribute, '');
    node.setAttribute('font-weight', '600');
    node.textContent = context.text;
    host.append(node);
    return () => node.remove();
  };
  return {
    [ChartContentSlotName.Title]: {...text[ChartContentSlotName.Title], render: html('strong', 'data-custom-title')},
    [ChartContentSlotName.Tooltip]: {...text[ChartContentSlotName.Tooltip], render: html('strong', 'data-custom-tooltip')},
    [ChartContentSlotName.Legend]: {...text[ChartContentSlotName.Legend], render: html('em', 'data-custom-legend')},
    [ChartContentSlotName.AxisLabel]: {...text[ChartContentSlotName.AxisLabel], render: svg('data-custom-axis')},
    [ChartContentSlotName.DataLabel]: {...text[ChartContentSlotName.DataLabel], render: svg('data-custom-label')},
  };
}

// Add <div id="chart"></div> in the HTML for this module.
const host = document.getElementById('chart');
if (!host) throw new Error('Missing #chart');

const data: ChartData = {
  "type": "column",
  "axes": {
    "x": {
      "type": "category",
      "values": [
        {
          "id": "period-0",
          "label": "Periodo 1"
        },
        {
          "id": "period-1",
          "label": "Periodo 2"
        },
        {
          "id": "period-2",
          "label": "Periodo 3"
        },
        {
          "id": "period-3",
          "label": "Periodo 4"
        },
        {
          "id": "period-4",
          "label": "Periodo 5"
        },
        {
          "id": "period-5",
          "label": "Periodo 6"
        }
      ]
    },
    "y": {
      "type": "linear"
    }
  },
  "series": [
    {
      "id": "series-0",
      "name": "Serie 1",
      "data": [
        {
          "id": "series-0-0",
          "x": "period-0",
          "y": 4200
        },
        {
          "id": "series-0-1",
          "x": "period-1",
          "y": 6100
        },
        {
          "id": "series-0-2",
          "x": "period-2",
          "y": 5300
        },
        {
          "id": "series-0-3",
          "x": "period-3",
          "y": null
        },
        {
          "id": "series-0-4",
          "x": "period-4",
          "y": 7200
        },
        {
          "id": "series-0-5",
          "x": "period-5",
          "y": 6800
        }
      ]
    },
    {
      "id": "series-1",
      "name": "Serie 2",
      "data": [
        {
          "id": "series-1-0",
          "x": "period-0",
          "y": 3300
        },
        {
          "id": "series-1-1",
          "x": "period-1",
          "y": 4800
        },
        {
          "id": "series-1-2",
          "x": "period-2",
          "y": 0
        },
        {
          "id": "series-1-3",
          "x": "period-3",
          "y": -5100
        },
        {
          "id": "series-1-4",
          "x": "period-4",
          "y": 6400
        },
        {
          "id": "series-1-5",
          "x": "period-5",
          "y": 5900
        }
      ]
    }
  ]
};
const options: ChartOptions = {
  "title": "Ingresos por periodo",
  "locale": "es",
  "theme": "light",
  "height": 380,
  "animation": {
    "enabled": false
  },
  "formatting": {
    "locale": "es-ES",
    "number": {
      "minimumFractionDigits": 2,
      "maximumFractionDigits": 2,
      "style": "currency",
      "currency": "EUR",
      "currencyDisplay": "code",
      "currencySign": "standard"
    }
  },
  "appearance": {
    "colors": [
      "#2c6ed5",
      "#698e37"
    ],
    "markers": true,
    "dataLabels": true,
    "labelLimit": 8
  },
  "hiddenSeriesIds": [],
  "legend": {
    "position": "bottom"
  },
  "tooltip": {
    "crosshair": true,
    "content": "shared"
  },
  "references": [
    {
      "id": "comparison",
      "axis": "y",
      "value": 4081.818181818182
    }
  ],
  "referenceLabels": [
    {
      "id": "comparison",
      "text": "Media: 4081,82 EUR"
    }
  ],
  "referenceStyles": [
    {
      "id": "comparison",
      "color": "#875310",
      "dash": "dashed",
      "width": 1.5
    }
  ],
  "responsive": [
    {
      "maxWidth": 430,
      "options": {
        "height": 320,
        "tooltip": {
          "placement": "docked"
        },
        "appearance": {
          "dataLabels": false
        },
        "axes": {
          "y": {
            "numberFormat": {
              "minimumFractionDigits": 0,
              "maximumFractionDigits": 0,
              "style": "currency",
              "currency": "EUR",
              "currencyDisplay": "narrowSymbol",
              "currencySign": "standard",
              "notation": "compact"
            }
          }
        }
      }
    }
  ]
};
const result = createChart(host, data, options, {
  instanceId: 'custom',
  content: createContent(options, false, true),
});
if (result.status !== 'ok') throw new Error(result.diagnostic.message);
export const chart = result.value;

// Call chart.destroy() when the host is removed.

Título

Añade jerarquía visual al título. Usa el texto portable para conservar el mismo nombre accesible y título al exportar.

Tooltip

Presenta la observación activa. El contexto contiene sus datos y puede incluir series de la misma posición cuando el tooltip es compartido.

Leyenda

Personaliza el nombre visible de la serie. El gráfico conserva los botones, el estado de visibilidad y su navegación por teclado.

Etiquetas de los ejes

El contexto distingue el eje X, el eje Y y el secundario, y aporta el valor original de la marca. Utiliza un elemento tspan para la presentación SVG.

Etiquetas de datos

Presenta el valor junto a su marca. Activa appearance.dataLabels en una gráfica compatible. El texto de partida ya incorpora el formato aplicado.