1.2.0 • Published 7 months ago

@lg-charts/core v1.2.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
7 months ago

Core Chart Components

Library of composable charting components that provides a way to create interactive charts rendered on canvas.

npm (scoped)

Installation

Yarn

yarn add @lg-charts/core

NPM

npm install @lg-charts/core

Basic Chart Example

import { Chart, ChartGrid, ChartHeader, Line, XAxis, YAxis, type ChartStates } from '@lg-charts/core';

<Chart onZoomSelect={handleZoom} state={ChartStates.Unset}>
  <ChartHeader title="My Chart" />
  <ChartGrid vertical={false}>
  <XAxis type="time" />
  <YAxis type="value" formatter={(value) => `${value}GB`} />
  <EventMarkerPoint
    label='2024/01/04 (value 3)'
    message='Critical event occurred'
    position={[new Date(2020, 01, 04), 3]}
    level='warning'
  />
  <EventMarkerLine
    label='2024/01/02'
    message='Something happened of note'
    position={new Date(2020, 01, 02)}
    level='info'
  />
  <ThresholdLine
    position={3}
    label='Value Limit'
    value='3'
  />
  <Line
    name="Series 1"
    data={[
      [new Date(2020, 01, 01), 0],
      [new Date(2020, 01, 02), 1],
      [new Date(2020, 01, 03), 2],
      [new Date(2020, 01, 04), 3],
      [new Date(2020, 01, 05), 4],
    ]}
  />
  <Line
    name="Series 2"
    data={[
      [new Date(2020, 01, 01), 4],
      [new Date(2020, 01, 02), 3],
      [new Date(2020, 01, 03), 2],
      [new Date(2020, 01, 04), 1],
      [new Date(2020, 01, 05), 0],
    ]}
  />
</Chart>;

Parent Components

Chart

Chart container component.

Props

NameDescriptionTypeDefault
state (optional)The state of the chart.ChartStates ('unset \| 'loading')'unset'
groupId (optional)Charts with the same groupId will have their tooltips synced across charts.string
onChartReady (optional)Callback to be called when chart is finished rendering.() => void
onZoomSelect (optional)Callback to be called when a zoom selection is made if zoomSelect is enabled.(e: ZoomSelectionEvent) => void
zoomSelect (optional)Enable zoom select (click and drag area selection) for either axis.{ xAxis?: boolean; yAxis?: boolean }{ xAxis: false, yAxis: false }

Note: Callback passed to onZoomSelect callback receives the following ZoomSelectionEvent as an argument:

ZoomSelectionEvent = {
  // present if xAxis is enabled
  xAxis?: { startValue: number; endValue: number };
  // present if yAxis is enabled
  yAxis?: { startValue: number; endValue: number };
}

Child Components

Line

Component that takes in data points and renders a single line on the chart.

Props

NameDescriptionTypeDefault
nameUnique name used to identify the series. Important note: If two lines have the same name, only one will be rendered.string
dataData array of tuples that represent x and y coordinates in the series.Array<[string \| number \| Date, string \| number \| Date]>

ChartHeader

Component for rendering a header in a chart.

Props

NameDescriptionTypeDefault
titleThe title to display in the chart header.string
showDivider (optional)When true, renders a dividing line on top of header. Useful when stacking charts, such as in a ChartGroup.boolean
headerContent (optional)Content that will be rendered to the right of the title. Useful for adding components such as IconButton's that control functionality in the chart.React.ReactNode

ChartGrid

Component that displays grid lines on the chart.

Props

NameDescriptionTypeDefault
horizontal (optional)Show horizontal grid lines.booleantrue
vertical (optional)Show vertical grid lines.booleantrue

XAxis

Renders an x-axis.

Props

NameDescriptionTypeDefault
typeType of axis.'log' \| 'time' \| 'value'
label (optional)Label name to be rendered on the axis.string
formatter (optional)Callback function for formatting tick values.(value: string, index: number) => string

YAxis

Renders a y-axis.

Props

NameDescriptionTypeDefault
typeType of axis.'log' \| 'time' \| 'value'
label (optional)Label name to be rendered on the axis.string
formatter (optional)Callback function for formatting tick values.(value: string, index: number) => string

ChartTooltip

Renders a tooltip onto the chart.

Props

NameDescriptionTypeDefault
sort (optional)Custom sort function, used to sort list of series. List will be sorted descending by value by default.(seriesA: SeriesInfo, seriesB: SeriesInfo) => numberdescending by default
seriesNameFormatter (optional)Callback function for formatting the name string for each series.(name: string) => string \| ReactNode
seriesValueFormatter (optional)Callback function for formatting the value string for each series.(value: number \| string \| Date) => string \| ReactNode
headerFormatter (optional)Callback function for formatting the header string.(value: number \| string) => string \| ReactNode

Note: SeriesInfo is of type { name: string; value: string | number | Date; }

EventMarkerLine

Renders a vertical line marker at a specific point on the x-axis to annotate an event.

Props

NameDescriptionTypeDefault
positionPosition along the x-axis where the line should be placed.string \| number
messageAdditional message text shown in the tooltip when hovering.string
label (optional)Label text shown in the tooltip when hovering.string
level (optional)Visual style of the marker indicating its severity.'warning' \| 'info''warning'

EventMarkerPoint

Renders a point marker at specific coordinates to annotate an event.

Props

NameDescriptionTypeDefault
positionCoordinates where the point should be placed x, y.[string \| number, string \| number]
messageAdditional message text shown in the tooltip when hovering.string
label (optional)Label text shown in the tooltip when hovering.string
level (optional)Visual style of the marker indicating its severity.'warning' \| 'info''warning'

ThresholdLine

Renders a horizontal dashed line at a specific value on the y-axis to indicate a threshold.

Props

NameDescriptionTypeDefault
positionPosition along the y-axis where the line should be placed.number
valueValue text shown after the label in the tooltip when hovering.string
label (optional)Label text shown in the tooltip when hovering.string
1.2.0

7 months ago

1.0.1

7 months ago

1.1.0

7 months ago

1.0.0

12 months ago

0.17.2

8 months ago

0.17.3

8 months ago

0.17.4

8 months ago

0.11.0

12 months ago

0.10.1

12 months ago

0.12.0

12 months ago

0.11.1

12 months ago

0.10.2

12 months ago

0.13.0

10 months ago

0.12.1

11 months ago

0.12.2

11 months ago

0.15.0

9 months ago

0.14.1

10 months ago

0.12.3

11 months ago

0.16.0

9 months ago

0.15.1

9 months ago

0.12.4

10 months ago

0.17.0

9 months ago

0.12.5

10 months ago

0.18.0

8 months ago

0.17.1

9 months ago

0.10.0

12 months ago

0.9.0

12 months ago

0.8.1

1 year ago

0.8.0

1 year ago

0.6.2

1 year ago

0.8.3

1 year ago

0.8.2

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.7.0

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.3.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago