Skip to content

API Biểu đồ khoảng cách

Thể hiện khoảng cách giữa hai con số và để cây cột truyền tải trọng điểm - xem demo Biểu đồ khoảng cách.

Nhập

ts
import "@michi-vz/wc/gap-chart";
// <michi-vz-gap-chart> is now defined
ts
import { mountGapChart } from "@michi-vz/core";

const chart = mountGapChart(el, props);

Thuộc tính

PropTypeDefaultDescription
dataSet*GapDataItem[]-Array of rows, one horizontal value1->value2 gap bar per item
titlestring-Optional chart title rendered above the plot
colorMode"label" | "shape""label"Whether marks are colored per row label ("label", default) or per role/shape via shapeColorsMapping ("shape")
shapeColorsMappingShapeMapping-When colorMode is "shape", the colors for the value1, value2, and gap parts
shapesLabelsMappingShapeMapping-Optional display labels for the value1/value2/gap roles (e.g. legend captions)
filterFilter-Top-N / sort filter applied to the data before rendering
timelineboolean | TimelinePeriodConfig-Opt-in "play through years": snapshots one period at a time over the distinct per-row `date` values, with a headless controller (`chart.timeline()`) plus an optional built-in play button + scrubber. Off by default; requires rows with `date`. The user's `filter` still applies within each period.
shapeValue1"circle" | "square" | "triangle""circle"Marker shape for the value1 endpoint: "circle" (default), "square", or "triangle"
shapeValue2"circle" | "square" | "triangle""circle"Marker shape for the value2 endpoint: "circle" (default), "square", or "triangle"
xAxisDataType"date_annual" | "date_monthly" | "number""number"How x values are parsed and formatted: yearly dates, monthly dates, or plain numbers
xAxisDomain[number, number]-Fix the value-axis range as [min, max] instead of the derived zero-baseline domain (e.g. zoom a life-expectancy story into its 35-90 band)
interactiveRowLabelsbooleanfalseMake the row labels interactive: hovering or focusing a label draws a leader line to its row's marks, highlights the row, and shows its tooltip; clicking pins the tooltip. Labels become keyboard-focusable. Default false.
xAxisFormat(d: number | string) => string-Formats an x tick value into its display label
yAxisFormat(d: number | string) => string-Formats a y tick value into its display label
ticksnumber5Approximate number of axis ticks to generate
tickValuesArray<number | Date>-Explicit tick values, overriding the generated ones
enableExplicitTickValuesboolean-When false, ignore `tickValues` for tick placement and GapChart's mark-scale domain, letting the chart use its data-derived domain and generated ticks.
tickHtmlWidthnumber100Width in px of the HTML y-axis label box, which ellipsizes longer labels (default 100)
squareRadiusnumber2Corner radius in px for square markers (default 2)
showZeroLineForXAxisbooleanfalseDraw a solid vertical line at x=0 on the value axis (diverging charts). Default false.
maxBarHeightnumber-Cap each row's thickness (px). When few rows would otherwise balloon the bandwidth (a scaleBand stretched over the full plot height), the band range shrinks to yield exactly this thickness and is centred in the plot (symmetric whitespace), so a 1-2 row chart reads tidily instead of a single row floating mid-plot. No-op for dense charts whose natural bandwidth is already below the cap. Mirrors ComparableBarChart's `maxBarHeight`.
showLegendboolean-Whether to render a legend
legendAlign"left" | "center" | "right"-Horizontal alignment of the legend: "left", "center", or "right"
tooltipFormatter(d: GapDataItem) => string-Returns custom tooltip HTML for a hovered datum (sanitized before it is inserted)
isLoadingboolean-Show the loading overlay and skip the no-data check (legacy michi-vz parity).
isNodataboolean | ((dataSet: GapDataItem[] | null | undefined) => boolean)-No-data override: boolean, or a predicate on the data; default = empty data.
noDataLabelstring-Text for the vanilla default no-data overlay (ignored when suppressed).
suppressDefaultOverlayboolean-A framework wrapper sets this to render its OWN loading/no-data node instead.
onHighlightItem(item: GapDataItem | null) => void-Called when the hovered/highlighted label(s) change
Common props - shared by every chart (14)
PropTypeDefaultDescription
widthnumber1000Chart width in pixels
heightnumber500Chart height in pixels
marginMargin{ top: 50, right: 150, bottom: 100, left: 150 }Inner margins (top/right/bottom/left, in px) reserved for axes, titles, and labels
colorsstring[]-Categorical palette for series/labels without an explicit colour or colorsMapping entry
colorsMappingRecord<string, string>-Explicit label -> colour map; takes precedence over the palette and per-item colours
highlightItemsstring[]-Labels to emphasise; all other marks dim
disabledItemsstring[]-Labels to hide and exclude from scales/stacks
renderer"svg" | "canvas" | "webgpu""svg"Render as inline SVG (default) or to a canvas (faster for large datasets); getContext() is identical either way
localestring-BCP-47 locale used for number and date formatting
skipColorMappingDispatchbooleanfalseExternal-CSS mode: unmapped labels resolve to transparent and onColorMappingGenerated is not emitted, so mark colours come from your CSS via the data-label-safe contract
enableTransitionsbooleantrueAnimate updates with CSS transitions (default true)
onColorMappingGenerated(mapping: Record<string, string>) => void-Called with the resolved label -> colour map after the chart assigns colours
onChartDataProcessed(context: ChartContext) => void-Called with the renderer-agnostic ChartContext whenever the data is (re)processed
onDataWarning(warnings: DataWarning[]) => void-Called with any non-fatal data warnings (duplicate labels, non-finite values, non-monotonic dates, ...)

Sự kiện

Web component phát ra (dispatch) các CustomEvent nổi bọt (bubbling) sau đây (engine cũng phơi bày các sự kiện tương tự thông qua các callback on* trong bảng ở trên):

Sự kiệnChi tiếtKích hoạt khi
michi-vz:highlightstring[]trạng thái nổi bật lúc di chuột thay đổi
michi-vz:colormappingRecord<string, string>một ánh xạ màu được tạo ra
michi-vz:dataprocessedChartContextdữ liệu được xử lý (lại)
michi-vz:datawarningDataWarning[]phát hiện cảnh báo đầu vào

getContext()

mountGapChart(el, props).getContext() trả về GapChartContext độc lập với renderer (số liệu thống kê có cấu trúc + một bản tóm tắt bằng ngôn ngữ tự nhiên có tính xác định + một bảng hỗ trợ khả năng tiếp cận a11y). Xem ngữ cảnh LLM.

Nguồn

Các thuộc tính (props) được định kiểu là GapChartProps trong @michi-vz/core.