Class BarChart<CursorResultTableBackgroundType>

Chart type for visualizing categorical data as Bars. Supports Positive and Negative data sets (baseline 0), and Bipolar data sets. These are automatically detected.

BarChart can be created in two different ways - to learn more about creation time configuration of BarChart, please refer to:

BarChart features

  1. Axes

BarChart has a Category Axis and Value Axis. These can be referenced with categoryAxis and valueAxis properties. For their available APIs, see BarChartCategoryAxis and BarChartValueAxis respectively.

  1. Data input

BarChart supports a handful of different syntaxes for data input. See setData for more details.

  1. Cursor

Auto cursor is activated when the users mouse is over a bar. It displays information about the hovered bar to the user over the chart in a result table.

Auto cursor can be configured in a variety of ways;

  • setCursorMode | set auto cursor behavior.
  • setCursor | style auto cursor.
  • BarChart.setCursorResultTableFormatter | configure formatting of result table contents.
  1. LegendBox

BarChart has built-in legend box functionality for listing the bars in a user interface. The legend box also provides additional logic, like hiding selected series by clicking on the legend box.

Legend box is added using addLegendBox.

  1. Title

BarChart has a built-in title component, which can be configured using setTitle.

  1. Backgrounds

BarChart contains two separate background components:

  1. UI Elements

Custom UI elements can be placed on BarChart in same way as all other charts, using addUIElement.

  1. Sorting

BarChart has built-in sorting functionality, which can be configured with setSorting.

  1. Bar styling

Each bar in BarChart can be individually styled. See BarChartBar for more details.

Other APIs worthy of mention:

  • Labels can be configured with setCategoryLabels, setValueLabels and setLabelFittingEnabled.
  • Empty space around BarChart can be configured with setPadding.
  • Additional margin around chart title can be configured with setTitleMargin.
  • All animations can be conveniently controlled with setAnimationsEnabled.
  • BarChart can be removed permanently with dispose.
  • Some useful events that can be subscribed to:
    • Resize events (BarChart.onResize).
    • Background events (BarChart.onBackgroundMouseMove).
    • Series Background events (BarChart.onSeriesBackgroundMouseMove).

Type Parameters

Hierarchy

Implements

Properties

_isPanelResized: boolean = true

Flag that is set whenever Panel or any scale is resized.

Will be handled before plot to update scale and trigger resize event just once per frame.

background: Eventer<LCJSInteractionEventMap, any> = ...

Interface for attaching listeners to user interaction events (click, pointerenter, etc.) on chart background.

 // Example syntax
chart.background.addEventListener('click', (event) => {
console.log(event)
})

For syntax examples, refer to EventInterface. Available event keys are listed under LCJSInteractionEventMap

Please note that many chart types have a separate "series background" (area enclosed by axes), which has its own separate events. This is accessed via seriesBackground property.

categoryAxis: BarChartCategoryAxis

Reference to the Category Axis of bar chart.

coordsBars: "barChart" = 'barChart'

Selector for coordinate system of the Bars.

This selector can be used for translating locations relative to Bars to other coordinate systems and vice versa.

For example, in order to:

  • Position LCJS UI elements in relative to Bar locations.
  • Find client coordinate relative to a Bar, for example to position external HTML content above them.
  • etc.

See translateCoordinate for more detailed use case information and example usage.

coordsClient: "client" = 'client'

Selector for "client" Coordinate System.

This references the coordinate system used in HTML. It starts at top left of the web page and is measured in pixels. For example, { x: 100, y: 20 } corresponds to 100 pixels from left and 20 pixels from top.

JavaScript events are tracked and HTML elements are positioned in the client coordinate system.

This selector can be used for translating client coordinates to other coordinate systems and vice versa. For example, in order to:

  • Position LCJS UI elements in client coordinates
  • Find client coordinate that matches a location along LCJS Axis or Chart.
  • etc.

See translateCoordinate for more detailed use case information and example usage.

coordsRelative: "relative" = 'relative'

Selector for "relative" Coordinate System.

This coordinate system is relative to the bottom left corner of the Control (chart/dashboard/etc.), and is measured as pixels. For example, { x: 100, y: 20 } corresponds to 100 pixels from left and 20 pixels from bottom.

This selector can be used for two purposes:

Positioning LCJS UI elements in pixels:

 // Position UI element in pixels by supplying `Control.coordsRelative` as its positioning system.
const textBox = Control.addUIElement(UIElementBuilders.TextBox, Control.coordsRelative)
.setOrigin(UIOrigins.LeftBottom)
.setPosition({ x: 100, y: 20 })

Translations between coordinate systems:

Use with translateCoordinate method to translate coordinates from "relative" to another coordinate system.

engine: PublicEngine

Interface for end user API of the LCJS engine. It provides some useful capabilities over the area enclosed by a single LCJS context (which can be just a single chart, or a Dashboard with several charts).

removePanel: ((panel: Panel) => void)

Type declaration

    • (panel: Panel): void
    • Parameters

      Returns void

seriesBackground: Eventer<LCJSInteractionEventMap, any> = ...

Interface for attaching listeners to user interaction events (click, pointerenter, etc.) on chart series background (area enclosed by axes).

 // Example syntax
chart.seriesBackground.addEventListener('click', (event) => {
console.log(event)
})

For more syntax examples, refer to EventInterface. Available event keys are listed under LCJSInteractionEventMap

title: Eventer<LCJSInteractionEventMap, any> = ...

Interface for attaching listeners to user interaction events (click, pointerenter, etc.) on chart title.

 // Example syntax
chart.title.addEventListener('click', (event) => {
console.log(event)
})

For syntax examples, refer to EventInterface. Available event keys are listed under LCJSInteractionEventMap

uiScale: LinearScaleXY

Scale for panel area in percentages (0-100).

While it is not functionally equal to this, using coordsRelative coordinate system is preferred (more confidence for long term support).

Reference to the Value Axis of bar chart.

Methods

  • Add manually controlled Cursor object. These have exactly same functions as built-in cursors but they can be freely controlled by application logic.

     const cursor = chart.addCursor()
    

    Styling works same as built-in cursors (e.g. setCursor).

    Position is set using setPosition method and displayed content using setResultTable(table => table.setContent(...)) For more details, see Developer documentation > Features > Cursor > Manual cursors

    Returns

    Cursor object.

    Type Parameters

    Parameters

    • cursorBuilder: CursorBuilder2D<ResultTableBackgroundType> = ...

      Builder for cursor. Can be used to tweak a handful of properties which can't be changed during runtime.

    Returns Cursor2D<ResultTableBackgroundType>

  • Add callback function to be triggered when specified event is fired.

     // Example syntax
    object.addEventListener('click', (event) => {
    console.log(event)
    })

    Some classes also report extra information about the interacted object with the second parameter:

     // Most series share information about interacted data point
    series.addEventListener('click', (event, info) => {
    console.log(info)
    })

    Optional third parameter allows registering event handlers that will automatically remove themselves after first trigger:

     // Example this listener will only fire once
    object.addEventListener('click', (event) => {})

    Each class has its own list of supported events. Some events are from HTML standard (click, pointerdown, etc.), while others are own events from LightningChart JS (dispose, resize, etc.)

    To find what events are available, you can try following:

    • If your development environment has TypeScript enabled, just write addEventListener and see what possible event types the IDE suggests. These APIs are strongly typed, and even the callback event will be correctly typed.
    • Otherwise, open the class section in API documentation and check out which interface K type parameter extends.

    Type Parameters

    Parameters

    Returns void

  • Add a legendbox.

    Legendbox is a type of UI element, that floats inside the chart/component it is created inside. It can be freely moved around with user interactions, as well as positioned in application code.

    The purpose of legendbox is to describe the series and other visual components of the chart, by displaying their names and colors. Hovering over a series' legendbox entry will highlight that series, and clicking on the entry will toggle that series' visibility.

    Legendbox alignment:

    Alignment of legendbox can be selected by supplying one of the available LegendBoxBuilders to addLegendBox:

     // Default (vertical) LegendBox.
    const legendBox = ChartXY.addLegendBox()

    // Horizontal LegendBox.
    const horizontalLegendBox = ChartXY.addLegendBox(LegendBoxBuilders.HorizontalLegendBox)

    Custom Legendbox positioning:

    By default LegendBoxes are placed on the right side, or bottom of the chart (depending on alignment).

    A custom location can be configured with UIElement API:

    Position coordinate system is specified when creating legendbox.

    1. LegendBox with default positioning coordinate system.
     addLegendBox( LegendBoxBuilders.VerticalLegendBox )
    // Position = [0, 100] as percentages.
    .setPosition({ x: 50, y: 50 })
    1. Position in pixel coordinate system.
     addLegendBox( LegendBoxBuilders.VerticalLegendBox, chart.coordsRelative )
    // Position = pixels.
    .setPosition({ x: 300, y: 100 })
    1. Position on Axes.
     addLegendBox( LegendBoxBuilders.VerticalLegendBox, { x: chartXY.getDefaultAxisX(), y: chartXY.getDefaultAxisY() } )
    // Position = Axis values.
    .setPosition({ x: 5, y: 5 })

    Returns

    LegendBox

    Parameters

    • builder: UILegendBoxBuilder<InternalBackground> = _legendBoxBuilder

      LegendBoxBuilder. If omitted, VerticalLegendBox will be selected. Use LegendBoxBuilders for selection.

    • scale: UserScaleDefinition = ...

      Optional parameter for altering the coordinate system used for positioning the LegendBox. Defaults to whole Chart in percentages [0, 100].

    Returns LegendBox<UIBackground>

  • Add a stand-alone UIElement using a builder.

    Example usage:

    1. TextBox with default positioning coordinate system.
     addUIElement( UIElementBuilders.TextBox )
    // Position = [0, 100] as percentages.
    .setPosition({ x: 50, y: 50 })
    1. Position in pixel coordinate system.
     addUIElement( UIElementBuilders.TextBox, chart.coordsRelative )
    // Position = pixels.
    .setPosition({ x: 300, y: 100 })
    1. Position on Axes.
     addUIElement( UIElementBuilders.TextBox, { x: chartXY.getDefaultAxisX(), y: chartXY.getDefaultAxisY() } )
    // Position = Axis values.
    .setPosition({ x: 5, y: 5 })

    Returns

    Object that fulfills interfaces: UIElementType (typeparam) and UIElement

    Type Parameters

    Parameters

    • builder: UIElementBuilder<UIElementType> = ...

      UIElementBuilder. If omitted, TextBoxBuilder will be selected. Use UIElementBuilders for selection.

    • scale: UserScaleDefinition = ...

      Optional parameter for altering the coordinate system used for positioning the UIElement. Defaults to whole Chart in percentages [0, 100].

    Returns UIElementType & UIElement

  • Permanently destroy the component.

    To fully allow Garbage-Collection to free the resources used by the component, make sure to remove any references to the component and its children in application code.

    let chart = ...BarChart()
    let axisX = chart.getDefaultAxisX()
    // Dispose Chart, and remove all references so that they can be garbage-collected.
    chart.dispose()
    chart = undefined
    axisX = undefined

    Returns

    Object itself for fluent interface

    Returns BarChart<CursorResultTableBackgroundType>

  • Get reference to a particular BarChartBar. The match is done against the category of bars and optionally also with subCategory.

     // Example
    barChart.setData([
    { category: 'Category 1', value: 10 },
    { category: 'Category 2', value: 12 },
    ])
    const bar = barChart.getBar('Category 1')
     // Example, grouped bar chart
    barChart.setDataGrouped(
    ['Cat 1', 'Cat 2'],
    [
    { subCategory: 'Scat 1', values: [10, 20] },
    { subCategory: 'Scat 2', values: [5, 6] },
    ]
    )
    const bar = barChart.getBar('Cat 1', 'Scat 2')

    This method throws an error if the Bar is not found or input arguments are ambiguous (for example, stacked bar chart and sub category wasn't supplied).

    Returns

    Reference to the BarChartBar with matching category.

    Parameters

    • category: string

      Category that is attempted to match against existing bars.

    • Optional subCategory: string

      Sub category that is attempted to match against existing bars.

    Returns BarChartBar

  • Get theme effect enabled on component or disabled.

    A theme can specify an Effect to add extra visual oomph to chart applications, like Glow effects around data or other components. Whether this effect is drawn above a particular component can be configured using the setEffect method.

     // Example, disable theme effect from a particular component.
    Component.setEffect(false)

    For the most part, theme effects are enabled by default on most components.

    Theme effect is configured with effect property.

    Returns

    Boolean that describes whether drawing the theme effect is enabled around the component or not.

    Returns boolean

  • Get margin around each bar along category axis as percentage of the bar thickness. For example, 0.1 = on both left and right side of bar there is a 10% margin. Actual thickness of bar depends on chart size, but for 100 px bar that would be 10 px + 10 px margin.

    Valid value range is between [0, 0.49].

    Returns

    Margin around each bar along category axis as percentage of bar thickness.

    Returns number

  • Beta

    Get rounded-ness of corners.

    Returns

    Number or undefined.

    Introduced in v7.0. API might be changed depending on user feedback.
    

    Returns undefined | number

  • Get reference to the built-in cursor object of the chart.

    Returns

    Generic cursor object.

    Returns Cursor2D<CursorResultTableBackgroundType>

  • Get state of automatic label fitting.

    This is enabled by default.

    Returns

    true or false

    Returns boolean

  • Get label fitting margins.

    Returns

    Margins as pixels.

    Returns Margin

  • Get theme effect enabled on component or disabled.

    A theme can specify an Effect to add extra visual oomph to chart applications, like Glow effects around data or other components. Whether this effect is drawn above a particular component can be configured using the setEffect method.

     // Example, disable theme effect from a particular component.
    Component.setEffect(false)

    For the most part, theme effects are enabled by default on most components.

    Theme effect is configured with effect property.

    Returns

    Boolean that describes whether drawing the theme effect is enabled around the component or not.

    Returns boolean

  • Get size of control as pixels.

    For stand-alone component, the size will be equal to the size of its containing HTML <div> (Control.engine.container)

    For component inside Dashboard, the size will only include the component itself, so size can be less than the size of containing HTML <div>.

    Returns

    Object with x and y properties { x: number, y: number }, where both are pixel values.

    Returns Point

  • Get theme effect enabled on component or disabled.

    A theme can specify an Effect to add extra visual oomph to chart applications, like Glow effects around data or other components. Whether this effect is drawn above a particular component can be configured using the setEffect method.

     // Example, disable theme effect from a particular component.
    Component.setEffect(false)

    For the most part, theme effects are enabled by default on most components.

    Theme effect is configured with effect property.

    Returns

    Boolean that describes whether drawing the theme effect is enabled around the component or not.

    Returns boolean

  • Get current value labels configuration.

    Returns

    BarChartValueLabels object or undefined if labels are hidden.

    Returns undefined | BarChartValueLabels

  • Remove event listener added using addEventListener. The expected argument should be the exact same callback function that was supplied using addEventListener:

     // Basic example syntax
    const listener = () => {}
    obj.addEventListener('click', listener)
    obj.removeEventListener('click', listener)
     // Basic boilerplate of custom interaction when user drags on an object
    obj.addEventListener('pointerdown', (eventDown) => {
    let prevCoord = eventDown
    const handlePointerMove: LCJSInteractionEventListener<'pointermove'> = (eventMove) => {
    const delta = { x: eventMove.clientX - prevCoord.clientX, y: eventMove.clientY - prevCoord.clientY }
    prevCoord = eventMove
    console.log(delta, eventMove.clientX, eventMove.clientY)
    }
    const handlePointerUp: LCJSInteractionEventListener<'pointerup'> = (eventUp) => {
    window.removeEventListener('pointermove', handlePointerMove)
    window.removeEventListener('pointerup', handlePointerUp)
    }
    window.addEventListener('pointermove', handlePointerMove)
    window.addEventListener('pointerup', handlePointerUp)
    })

    Type Parameters

    Parameters

    • type: K
    • listener: ((event: BarChartEventMap[K], info: unknown) => unknown)

      Listener that was added using addEventListener.

    Returns void

  • Capture rendered state in an image file. Prompts the browser to download the created file.

    NOTE: The download might be blocked by browser/plugins as harmful. To prevent this, only call the method in events tied to user-interactions. From mouse-event handlers, for example.

    Has two optional parameters which directly reference JavaScript API HTMLCanvasElement.toDataURL. For supported image formats, compression quality, Etc. refer to:

    https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL

    Example usage:

    // Download 'screenshot.png'
    Panel.saveToFile('screenshot')
    // Attempt download 'maybeNotSupported.bmp'
    Panel.saveToFile('maybeNotSupported', 'image/bmp')
    // Attempt download jpeg.file with specified compression quality
    Panel.saveToFile('fileName', 'image/jpeg', 0.50)

    Remarks

    If 'type' is not supported by browser, an Error will be thrown.

    Parameters

    • fileName: string

      Name of prompted download file as string. File extension shouldn't be included as it is automatically detected from 'type'-argument.

    • Optional type: string

      A DOMString indicating the image format. The default format type is image/png.

    • Optional encoderOptions: number

      A Number between 0 and 1 indicating the image quality to use for image formats that use lossy compression such as image/jpeg and image/webp. If this argument is anything else, the default value for image quality is used. The default value is 0.92.

    Returns BarChart<CursorResultTableBackgroundType>

  • Enable/disable animation of bar category positions. This is enabled by default.

     // Example, disable category position animation.
    BarChart.setAnimationCategoryPosition(false)

    Returns

    Object itself.

    Parameters

    • enabled: boolean

      Boolean

    • speedMultiplier: number = 1

      Optional multiplier for category animation speed. 1 matches default speed.

    Returns BarChart<CursorResultTableBackgroundType>

  • Enable/disable animation of bar values. This is enabled by default.

     // Example, disable value animation.
    BarChart.setAnimationValues(false)

    Returns

    Object itself.

    Parameters

    • enabled: boolean

      Boolean

    • speedMultiplier: number = 1

      Optional multiplier for animation speed. 1 matches default speed.

    Returns BarChart<CursorResultTableBackgroundType>

  • Set FillStyle of chart background.

     // Example usage,
    ChartXY.setBackgroundFillStyle(new SolidFill({ color: ColorRGBA( 80, 0, 0 ) }))

    Related API:

    • Use SolidFill to describe a solid fill color.
    • Use ColorRGBA to create a color from Red, Green, Blue (and optionally) Alpha values in range [0, 255].

    Transparent chart backgrounds:

    LightningChart JS charts can be configured to be fully or partially transparent.

     // Example, partially transparent chart

    // Engine background exists under all LCJS components. In case of Dashboard, there is only 1 shared engine background.
    chart.engine.setBackgroundFillStyle(emptyFill)
    // Chart background covers every 1 chart. In case of Dashboard, every chart has its own chart background.
    chart.setBackgroundFillStyle(new SolidFill({ color: ColorRGBA(0, 0, 0, 100) }))
    // Some charts also have a separate series background.
    chart.setSeriesBackgroundFillStyle(new SolidFill({ color: ColorRGBA(0, 0, 0, 100) }))

    Returns

    Object itself

    Parameters

    Returns BarChart<CursorResultTableBackgroundType>

  • Set theme effect enabled on component or disabled.

    A theme can specify an Effect to add extra visual oomph to chart applications, like Glow effects around data or other components. Whether this effect is drawn above a particular component can be configured using the setEffect method.

     // Example, disable theme effect from a particular component.
    Component.setEffect(false)

    For the most part, theme effects are enabled by default on most components.

    Theme effect is configured with effect property.

    Returns

    Object itself.

    Parameters

    • enabled: boolean

      Theme effect enabled

    Returns BarChart<CursorResultTableBackgroundType>

  • Set margin around each bar along category axis as percentage of the bar thickness. For example, 0.1 = on both left and right side of bar there is a 10% margin. Actual thickness of bar depends on chart size, but for 100 px bar that would be 10 px + 10 px margin.

    Valid value range is between [0, 0.49].

     // Example, no margin between bars.
    BarChart.setBarsMargin(0)
     // Example, increased space between bars.
    BarChart.setBarsMargin(0.20)

    Returns

    Object itself.

    Parameters

    • margin: number

      Margin around each bar along category axis as percentage of bar thickness.

    Returns BarChart<CursorResultTableBackgroundType>

  • Configure how category labels are displayed in the BarChart. To see all configuration options, see BarChartCategoryLabels.

    To display labels inside or after bars, see setValueLabels.

     // Example, hide labels
    barChart.setCategoryLabels(undefined)
     // Example, change label color
    barChart.setCategoryLabels({
    labelFillStyle: new SolidFill({ color: ColorRGBA(255, 0, 0) })
    })
     // Example, change label font size. In this case, the previous label configuration is used as a reference so callback function is convenient.
    barChart.setCategoryLabels((labels) => ({
    labelFont: labels.labelFont.setSize(10)
    }))
     // Example, configure formatting
    barChart.setCategoryLabels({
    formatter: (info) => `${info.category} (${(info.value / 1000).toFixed(1)} k€)`,
    })

    Returns

    Object itself.

    Parameters

    Returns BarChart<CursorResultTableBackgroundType>

  • Beta

    Configure rounded-ness of corners.

     obj.setCornerRadius(10)             // 10 px rounding radius
    obj.setCornerRadius(undefined) // straight corners

    Parameters

    • radius: undefined | number

      Number (pixel radius) or undefined.

      Introduced in v7.0. API might be changed depending on user feedback.
      

    Returns BarChart<CursorResultTableBackgroundType>

  • Style chart cursor using a callback function. Available style APIs can depend on the type of chart.

     // Example syntax
    chart.setCursor((cursor) => cursor
    .setGridStrokeXStyle(new SolidLine({
    thickness: 1,
    fillStyle: new SolidFill({ color: ColorRGBA( 255, 0, 0 ) })
    }))
    )

    See Cursor2D, CursorXY or Cursor3D for all available methods for configuring the cursor.

    Example usage:

     // Example 1, disable Y Axis tick marker & grid line.
    chart.setCursor((cursor) => cursor
    .setTickMarkerYVisible(false)
    .setGridStrokeYStyle(emptyLine)
    )
     // Example 2, style cursor ResultTable.
    chart.setCursor((cursor) => cursor
    .setResultTable((resultTable) => resultTable
    .setOrigin(UIOrigins.LeftTop)
    .setTextFillStyle(new SolidFill({ color: ColorRGBA(255, 0, 0) }))
    .setTextFont((font) => font
    .setSize(12)
    .setFamily('sans-serif')
    )
    .setBackground((background) => background
    .setFillStyle(new SolidFill({ color: ColorRGBA(0, 0, 0, 0) }))
    )
    )
    )
     // Example 3, style cursor TickMarker X.
    chart.setCursor((cursor) => cursor
    .setTickMarkerX((tickMarker: UIPointableTextBox) => tickMarker
    .setTextFont((font) => font.setWeight('bold'))
    .setTextFillStyle(new SolidFill({ color: ColorRGBA(0, 255, 0) }))
    .setBackground((background) => background.setFillStyle(emptyFill).setStrokeStyle(emptyLine)),
    )
    )

    Returns

    Object itself for fluent interface.

    Parameters

    • mutator: Mutator<Cursor2D<CursorResultTableBackgroundType>>

      Callback function that receives reference to the charts cursor.

    Returns BarChart<CursorResultTableBackgroundType>

  • Set cursor formatting, controlling the text displayed in built-in cursor.

     chart.setCursorFormatting((_, hit, hits) => {
    return [
    ['Cursor pointing at'],
    [hit.series], // returning a series will display the series color and its name automatically.
    ['X', '', hit.axisX.formatValue(hit.x)], // utilizing axis formatValue is useful for considering active zoom level and type of axis
    ['Y', '', hit.y.toFixed(2)], // empty string '' results in gap between cells
    [{ text: 'Example', font: { weight: 'bold' }, fillStyle: fillRed }] // any cell can also be styled individually
    ]
    })

    Before overriding default cursor formatting, it is recommended to check if using setUnits or configuring Axis cursor formatting would be enough.

    In order to use series specific data properties (e.g. Heatmap sample "intensity"), you should use type guards to assert the type of the SolveResult:

     // Example of using type guard in cursor formatter
    Chart.setCursorFormatting((chart, hit, hits) => {
    if (!isHitHeatmap(hit)) return undefined
    return [hit.intensity.toFixed(1)]
    })

    More details in Developer documentation (Features > Cursor).

    Returns

    Object itself

    Parameters

    Returns BarChart<CursorResultTableBackgroundType>

  • Set cursor behavior. This affects both built-in cursor as well as any custom cursor connected using setCustomCursor.

    For possible values see SolveNearestMode. Additionally, you can supply undefined value to disable cursor completely.

     // Example, show 1 nearest solve result only
    chart.setCursorMode('show-nearest')
     // Example, disable cursor
    chart.setCursorMode(undefined)
     // Example, enable interpolation
    chart.setCursorMode('show-all-interpolated')

    Returns

    Object itself

    Parameters

    Returns BarChart<CursorResultTableBackgroundType>

  • Connect a custom cursor to the chart. This has 2 effects:

    1. The built-in cursor is disabled.
    2. The provided callback function is called whenever the custom cursor should be updated, along with the data that the cursor should be pointing at.

    Custom cursors are still affected by other cursor behavior controls such as:

    The custom cursor can be anything defined by the user, such as:

    • Using other LCJS means of displaying the cursor, like custom ticks, constant lines, text boxes, etc.
    • Displaying a cursor using HTML/JS/CSS
    • Displaying a cursor using UI framework, like Angular, React, Vue, Next, ...
     // Example of plugging in a custom cursor
    chart.setCustomCursor((event) => {
    if (event) {
    // Display custom cursor
    } else {
    // Hide custom cursor
    }
    })

    Returns

    Object itself

    Parameters

    • clbk: undefined | ((event: CursorTargetChangedEvent<SolveResultBar>) => unknown)

      undefined to restore built-in cursor or callback function that should be triggered to display custom cursor.

    Returns BarChart<CursorResultTableBackgroundType>

  • Set BarChart data, updating the visible bars.

    This method signature takes in an array of objects with category and optional value properties.

     // Example usage
    barChart.setData([
    { category: 'Category 1', value: 10 },
    { category: 'Category 2', value: 12 },
    ])

    In use cases with real-time updates, the recommended way to push value updates to existing bars is to call setData again.

    See also: setDataStacked setDataGrouped

    Returns

    Object itself

    Parameters

    • arg: {
          category: string;
          value?: number;
      }[]

      Array of objects with category and value properties.

    Returns BarChart<CursorResultTableBackgroundType>

  • Set BarChart data, updating the visible bars.

    This method signature takes a single object that can have any number of keys. Each key is interpreted as a category, and the respective value as the bar value.

     // Example usage
    barChart.setData({
    'Category 1': 10,
    'Category 2': 12,
    })

    In use cases with real-time updates, the recommended way to push value updates to existing bars is to call setData again.

    See also: setDataStacked setDataGrouped

    Returns

    Object itself

    Parameters

    • arg: {
          [key: string]: unknown;
      }

      Object with string keys and number values.

      • [key: string]: unknown

    Returns BarChart<CursorResultTableBackgroundType>

  • Set BarChart data, updating the visible bars.

    This method signature takes an array of numbers, where each number is a value for a bar. In this case, each bar is just assigned an automatic category like "Category 1".

     // Example usage
    barChart.setData([10, 12])

    In use cases with real-time updates, the recommended way to push value updates to existing bars is to call setData again.

    See also: setDataStacked setDataGrouped

    Returns

    Object itself

    Parameters

    • arg: number[]

      Number array of bar values.

    Returns BarChart<CursorResultTableBackgroundType>

  • Set BarChart data, updating the visible bars.

    This method signature takes in an array of strings as Categories, without any Values. It can be used to initialize the categories before data is available, for example to show the bars in a LegendBox:

     // Data is not yet available, but prepare legend.
    barChart.setData(categories)
    const legend = barChart.addLegendBox().add(barChart)

    See also: setDataStacked setDataGrouped

    Returns

    Object itself

    Parameters

    • arg: string[]

      Array of strings as categories

    Returns BarChart<CursorResultTableBackgroundType>

  • Beta

    Set BarChart data, updating the visible bars. This method accepts data for a Grouped Bar Chart, displaying it as such.

     BarChart.setDataGrouped(
    ['category 1' , 'category 2'],
    [
    { subCategory: 'sub category 1', values: [1, 2] },
    { subCategory: 'sub category 2', values: [3, 4] },
    { subCategory: 'sub category 3', values: [5, 6] },
    ]
    )

    See also: setData setDataStacked

    Released to public beta in v5.1.0. May be reworked according to customer feedback and experiences.
    

    Parameters

    • categories: string[]
    • data: {
          subCategory: string;
          values: number[];
      }[]

    Returns BarChart<CursorResultTableBackgroundType>

  • Beta

    Set BarChart data, updating the visible bars. This method accepts data for a Stacked Bar Chart, displaying it as such.

     BarChart.setDataStacked(
    ['category 1' , 'category 2'],
    [
    { subCategory: 'sub category 1', values: [1, 2] },
    { subCategory: 'sub category 2', values: [3, 4] },
    { subCategory: 'sub category 3', values: [5, 6] },
    ]
    )

    See also: setData setDataGrouped

    Released to public beta in v5.1.0. May be reworked according to customer feedback and experiences.
    

    Parameters

    • categories: string[]
    • data: {
          subCategory: string;
          values: number[];
      }[]

    Returns BarChart<CursorResultTableBackgroundType>

  • Enable or disable automatic label fitting.

    This is enabled by default.

     // Example, disable automatic label fitting
    barChart.setLabelFittingEnabled(false)

    Returns

    Object itself.

    Parameters

    • enabled: boolean

      true or false.

    Returns BarChart<CursorResultTableBackgroundType>

  • Set label fitting margins. This is only relevant if label fitting is enabled setLabelFittingEnabled. This is true by default.

    These margins describe extra space that is added around every labels collision box.

     // Example, configure specific fitting margin (10 pixels)
    barChart.setLabelFittingMargins(10)

    // Example, configure non-symmetric margins
    barChart.setLabelFittingMargins({ left: 5, right: 5, top: 0, bottom: 0 })

    Returns

    Object itself.

    Parameters

    • margins: undefined | number | Margin

      Margins as pixels or undefined to restore default behavior.

    Returns BarChart<CursorResultTableBackgroundType>

  • Set padding around Chart in pixels.

     // Example 1, specify complete padding (four sides).
    ChartXY.setPadding({ left: 16, right: 16, top: 32, bottom: 8 })
     // Example 2, specify only single padding.
    ChartXY.setPadding({ right: 64 })

    Returns

    Object itself

    Parameters

    • padding: number | Partial<Margin>

      Number with pixel margins for all sides or datastructure with individual pixel paddings for each side. Any side can be omitted, only passed values will be overridden.

    Returns BarChart<CursorResultTableBackgroundType>

  • Set theme effect enabled on component or disabled.

    A theme can specify an Effect to add extra visual oomph to chart applications, like Glow effects around data or other components. Whether this effect is drawn above a particular component can be configured using the setEffect method.

     // Example, disable theme effect from a particular component.
    Component.setEffect(false)

    For the most part, theme effects are enabled by default on most components.

    Theme effect is configured with effect property.

    Returns

    Object itself.

    Parameters

    • enabled: boolean

      Theme effect enabled

    Returns BarChart<CursorResultTableBackgroundType>

  • Set FillStyle of series background (area behind series).

     // Example usage,
    ChartXY.setSeriesBackgroundFillStyle(new SolidFill({ color: ColorRGBA( 60, 0, 0 ) }))

    Related API:

    • Use SolidFill to describe a solid fill color.
    • Use ColorRGBA to create a color from Red, Green, Blue (and optionally) Alpha values in range [0, 255].

    Transparent chart backgrounds:

    LightningChart JS charts can be configured to be fully or partially transparent.

     // Example, partially transparent chart

    // Engine background exists under all LCJS components. In case of Dashboard, there is only 1 shared engine background.
    chart.engine.setBackgroundFillStyle(emptyFill)
    // Chart background covers every 1 chart. In case of Dashboard, every chart has its own chart background.
    chart.setBackgroundFillStyle(new SolidFill({ color: ColorRGBA(0, 0, 0, 100) }))
    // Some charts also have a separate series background.
    chart.setSeriesBackgroundFillStyle(new SolidFill({ color: ColorRGBA(0, 0, 0, 100) }))

    Returns

    Object itself

    Parameters

    Returns BarChart<CursorResultTableBackgroundType>

  • Set the state for all Series in the Chart to highlight on mouse hover.

    Returns

    Object itself for fluent interface.

    Parameters

    • state: boolean

      True if all Series should be highlighted on mouse hover, false if not.

    Returns BarChart<CursorResultTableBackgroundType>

  • Configure automatic sorting of bars.

    The default value is BarChartSorting.Descending.

     // Example, disable sorting
    barChart.setSorting(BarChartSorting.None)
     // Example, ascending sorting
    barChart.setSorting(BarChartSorting.Ascending)
     // Example, descending sorting
    barChart.setSorting(BarChartSorting.Descending)
     // Example, alphabetical sorting
    barChart.setSorting(BarChartSorting.Alphabetical)
     // Example, custom sorting (ascending implementation)
    barChart.setSorting((a, b) => a.value - b.value)

    Returns

    Object itself.

    Parameters

    • sorter: undefined | BarChartSorter

      Sorting function or undefined to disable sorting.

    Returns BarChart<CursorResultTableBackgroundType>

  • Set text of Chart title.

    Returns

    Object itself for fluent interface.

    Parameters

    • title: string

      Chart title as a string.

    Returns BarChart<CursorResultTableBackgroundType>

  • Set theme effect enabled on component or disabled.

    A theme can specify an Effect to add extra visual oomph to chart applications, like Glow effects around data or other components. Whether this effect is drawn above a particular component can be configured using the setEffect method.

     // Example, disable theme effect from a particular component.
    Component.setEffect(false)

    For the most part, theme effects are enabled by default on most components.

    Theme effect is configured with effect property.

    Returns

    Object itself.

    Parameters

    • enabled: boolean

      Theme effect enabled

    Returns BarChart<CursorResultTableBackgroundType>

  • Specifies padding after chart title.

    This does not have an effect if title is hidden (empty FillStyle).

     // Example 1, specify vertical margins
    ChartXY.setTitleMargin({ top: 0, bottom: 10 })

    // Example 2, specify margins for all sides with same value for Title.
    ChartXY.setTitleMargin(40)

    Returns

    Chart itself for fluent interface

    Parameters

    • marginPixels: number | Partial<Margin>

      Gap after the chart title in pixels.

    Returns BarChart<CursorResultTableBackgroundType>

  • Configure how value labels are displayed in the BarChart.

    There are a handful of different value label positioning types in BarChart, which you can find in BarChartValueLabels. Labels can also be separately displayed before bars on the other side of category axis, see setCategoryLabels.

     // Example, hide labels
    barChart.setValueLabels(undefined)
     // Example, display value labels after bars
    barChart.setValueLabels({
    position: 'after-bar'
    })
     // Example, display value labels inside bars with black color
    barChart.setValueLabels({
    position: 'inside-bar',
    labelFillStyle: new SolidFill({ color: ColorRGBA(0, 0, 0) })
    })
     // Example, change label font size. In this case, the previous label configuration is used as a reference so callback function is convenient.
    barChart.setValueLabels((labels) => ({
    labelFont: labels.labelFont.setSize(10)
    }))
     // Example, configure formatting
    barChart.setValueLabels({
    formatter: (info) => `${info.category} (${(info.value / 1000).toFixed(1)} k€)`,
    })

    Returns

    Object itself.

    Parameters

    Returns BarChart<CursorResultTableBackgroundType>

  • Translate a coordinate in HTML client coordinate system to another coordinate system.

    (1) bars coordinate system:

     BarChart.seriesBackground.addEventListener('click', event => {
    const locationBars = chart.translateCoordinate(event, chart.coordsBars)
    // locationBars tells the clicked location relative to Bar Chart value and category axes.
    })

    (2) relative control coordinate system:

     const locationClient = { clientX: document.body.clientWidth * 0.2, clientY: document.body.clientHeight * 0.5 }
    const locationRelative = chart.translateCoordinate(locationClient, chart.coordsRelative)
    // locationRelative is in pixels relative to bottom left corner of the chart

    Relative coordinates can be used for positioning LightningChart JS UI components:

     const textBox = chart.addUIElement(UIElementBuilders.TextBox, chart.coordsRelative)
    // Left bottom of TextBox is positioned 20 pixels right and 20 pixels up from charts bottom left corner
    .setOrigin(UIOrigins.LeftBottom)
    .setPosition({ x: 20, y: 20 })

    NOTE: Currently coordinate translations can't be guaranteed to be in sync with latest updates to charts. For example, if you change axis interval, or add data to a series, you need to wait for 1 frame to be displayed before translateCoordinate will behave as expected.

     LineSeries.add(myData)
    requestAnimationFrame(() => {
    // translateCoordinate should now consider data added just now.
    })

    Type Parameters

    • T extends "relative" | "barChart"

    Parameters

    Returns T extends "relative" ? CoordinateXY : T extends "barChart" ? CoordinateBarChart : never

  • Translate a coordinate in Bars coordinate system to another coordinate system.

    (1) HTML client coordinate system:

     const locationBars = { iCategory: 0, value: 100 }
    const locationClient = chart.translateCoordinate(locationBars, chart.client)

    Client coordinates can be used to absolute position HTML elements using CSS, for example.

     myHTMLElement.style.position = 'absolute'
    myHTMLElement.style.left = locationClient.clientX
    myHTMLElement.style.top = locationClient.clientY

    (2) relative control coordinate system:

     const locationBars = { iCategory: 0, value: 100 }
    const locationRelative = chart.translateCoordinate(locationBars, chart.coordsRelative)
    // locationRelative is in pixels relative to bottom left corner of the chart

    Relative coordinates can be used for positioning LightningChart JS UI components:

     const textBox = chart.addUIElement(UIElementBuilders.TextBox, chart.coordsRelative)
    // Left bottom of TextBox is positioned 20 pixels right and 20 pixels up from charts bottom left corner
    .setOrigin(UIOrigins.LeftBottom)
    .setPosition({ x: 20, y: 20 })

    NOTE: Currently coordinate translations can't be guaranteed to be in sync with latest updates to charts. For example, if you change axis interval, or add data to a series, you need to wait for 1 frame to be displayed before translateCoordinate will behave as expected.

     LineSeries.add(myData)
    requestAnimationFrame(() => {
    // translateCoordinate should now consider data added just now.
    })

    Type Parameters

    • T extends "client" | "relative"

    Parameters

    Returns T extends "relative" ? CoordinateXY : T extends "client" ? CoordinateClient : never

  • Translate a coordinate from relative control coordinates to another coordinate system.

     // 10 pixels left and 20 pixels up from controls bottom left corner
    const locationRelative = { x: 10, y: 20 }
    const locationClient = chart.translateCoordinate(locationRelative, chart.coordsRelative, chart.coordsClient)

    Client coordinates can be used to absolute position HTML elements using CSS, for example.

     myHTMLElement.style.position = 'absolute'
    myHTMLElement.style.left = locationClient.clientX
    myHTMLElement.style.top = locationClient.clientY

    NOTE: Currently coordinate translations can't be guaranteed to be in sync with latest updates to charts. For example, if you change axis interval, or add data to a series, you need to wait for 1 frame to be displayed before translateCoordinate will behave as expected.

     LineSeries.add(myData)
    requestAnimationFrame(() => {
    // translateCoordinate should now consider data added just now.
    })

    Type Parameters

    • T extends "client" | "barChart"

    Parameters

    Returns T extends "client" ? CoordinateClient : T extends "barChart" ? CoordinateBarChart : never

  • Translate a coordinate in HTML client coordinate system to relative coordinates within the component.

     const locationClient = { clientX: document.body.clientWidth * 0.2, clientY: document.body.clientHeight * 0.5 }
    const locationRelative = chart.translateCoordinate(locationClient, chart.coordsRelative)
    // locationRelative is in pixels relative to bottom left corner of the chart

    Relative coordinates can be used for positioning LightningChart JS UI components:

     const textBox = chart.addUIElement(UIElementBuilders.TextBox, chart.coordsRelative)
    // Left bottom of TextBox is positioned 20 pixels right and 20 pixels up from charts bottom left corner
    .setOrigin(UIOrigins.LeftBottom)
    .setPosition({ x: 20, y: 20 })

    NOTE: Currently coordinate translations can't be guaranteed to be in sync with latest updates to charts. For example, if you change axis interval, or add data to a series, you need to wait for 1 frame to be displayed before translateCoordinate will behave as expected.

     LineSeries.add(myData)
    requestAnimationFrame(() => {
    // translateCoordinate should now consider data added just now.
    })

    Type Parameters

    • T extends "relative"

    Parameters

    Returns T extends "relative" ? CoordinateXY : never

  • Translate a coordinate from relative control coordinates to HTML client coordinate system.

     // 10 pixels left and 20 pixels up from controls bottom left corner
    const locationRelative = { x: 10, y: 20 }
    const locationClient = chart.translateCoordinate(locationRelative, chart.coordsRelative, chart.coordsClient)

    Client coordinates can be used to absolute position HTML elements using CSS, for example.

     myHTMLElement.style.position = 'absolute'
    myHTMLElement.style.left = locationClient.clientX
    myHTMLElement.style.top = locationClient.clientY

    NOTE: Currently coordinate translations can't be guaranteed to be in sync with latest updates to charts. For example, if you change axis interval, or add data to a series, you need to wait for 1 frame to be displayed before translateCoordinate will behave as expected.

     LineSeries.add(myData)
    requestAnimationFrame(() => {
    // translateCoordinate should now consider data added just now.
    })

    Type Parameters

    • T extends "client"

    Parameters

    • coordinate: CoordinateXY
    • srcCoordinateSystem: "relative"
    • targetCoordinateSystem: T

    Returns T extends "client" ? CoordinateClient : never