Charts

Line

LightweightCharts.Charts.lwc_lineFunction
lwc_line(Vector{LWCSimpleChartItem}; kw...) -> LWCChart

Creates a LWCChart object that contains line chart information. A general method that allows you to customize each chart node using LWCSimpleChartItem.

Wrapper function for Line.

Keyword arguments

Name::TypeDefault (Possible values)Description
price_scale_id::LWC_PRICE_SCALE_IDLWC_LEFT (LWC_RIGHT)Y-axis display side.
label_name::String""Chart name.
visible::BooltrueChart visibility.
precision::Int642Number of decimal places for y-axis values.
line_color::StringRandom colorLine color.
line_style::LWC_LINE_STYLESLWC_SOLID (LWC_DOTTED, LWC_DASHED, LWC_LARGE_DASHED, LWC_SPARSE_DOTTED)Line style.
line_width::Int641Line width.
line_type::LWC_LINE_TYPESLWC_SIMPLE (LWC_STEP, LWC_CURVED)Line type.
line_visible::BooltrueLine visibility.
point_markers_visible::BoolfalseDisplaying markers on line nodes.
point_markers_radius::Float644.0Size of markers.
crosshair_marker_visible::BooltrueCursor crosshair visibility.
crosshair_marker_radius::Float644.0Size of crosshair.
crosshair_marker_border_color::String"#758696"Border color of crosshair.
crosshair_marker_background_color::String"#4c525e"Background color of crosshair.
crosshair_marker_border_width::Float642.0Border width of the crosshair.
plugins::Vector{LWCPlugin}LWCPlugin[]Additional plugins.
source
lwc_line(timestamps::Vector{TimeType}, values::Vector{Real}; kw...) -> LWCChart
lwc_line(timestamps::Vector{Real}, values::Vector{Real}; kw...) -> LWCChart

Creates a LWCChart from the passed timestamps and values.

source
lwc_line(data::Vector{Tuple{TimeType,Real}}; kw...) -> LWCChart
lwc_line(data::Vector{Tuple{Real,Real}}; kw...) -> LWCChart

Creates a LWCChart from the passed data that describes a vector of timestamps and values.

source
lwc_line(values::Vector{Real}; kw...) -> LWCChart

Creates a LWCChart from the passed values (timestamps begin from 1970-01-01).

source
lwc_line(custom_data::Vector{Any}; kw...) -> LWCChart

Creates a LWCChart from the passed custom_data.

For more information see Custom data section.

source

Example

using LightweightCharts

t_values = round(Int64, time()) .+ collect(1:500)
x_values = map(x -> sin(x / 10), 1:500)

chart = lwc_line(
    t_values,
    x_values;
    label_name = "lwc_line",
    line_color = "#02c39a",
    line_width = 4,
    line_style = LWC_SOLID,
    line_type = LWC_CURVED,
    price_scale_id = LWC_RIGHT,
)

lwc_save("line_example.html", chart)

Baseline

LightweightCharts.Charts.lwc_baselineFunction
lwc_baseline(Vector{LWCSimpleChartItem}; kw...) -> LWCChart

Creates a LWCChart object that contains line chart information. A general method that allows you to customize each chart node using LWCSimpleChartItem.

Wrapper function for Baseline.

Keyword arguments

Name::TypeDefault (Possible values)Description
price_scale_id::LWC_PRICE_SCALE_IDLWC_LEFT (LWC_RIGHT)Y-axis display side.
label_name::String""Chart name.
visible::BooltrueChart visibility.
precision::Int642Number of decimal places for y-axis values.
base_value::LWCBaseValueLWCBaseValue("price", 0.0)The value relative to which larger or smaller values will be colored in the appropriate color.
top_fill_color1::String"rgba(38, 166, 154, 0.28)"The first color of the upper area.
top_fill_color2::String"rgba(38, 166, 154, 0.05)"The second color of the upper area.
top_line_color::String"rgba(38, 166, 154, 1)"Color of the upper area line.
bottom_fill_color1::String"rgba(239, 83, 80, 0.05)"The first color of the lower area.
bottom_fill_color2::String"rgba(239, 83, 80, 0.28)"The second color of the lower area.
bottom_line_color::String"rgba(239, 83, 80, 1)"Color of the lower area line.
line_width::Int641Line width.
line_style::LWC_LINE_STYLESLWC_SOLID (LWC_DOTTED, LWC_DASHED, LWC_LARGE_DASHED, LWC_SPARSE_DOTTED)Line style.
line_type::LWC_LINE_TYPESLWC_SIMPLE (LWC_STEP, LWC_CURVED)Line type.
line_visible::BooltrueLine visibility.
point_markers_visible::BoolfalseDisplaying markers on line nodes.
point_markers_radius::Float644.0Size of markers.
crosshair_marker_visible::BooltrueCursor crosshair visibility.
crosshair_marker_radius::Float644.0Size of crosshair.
crosshair_marker_border_color::String"#758696"Border color of crosshair.
crosshair_marker_background_color::String"#4c525e"Background color of crosshair.
crosshair_marker_border_width::Float642.0Border width of the crosshair.
plugins::Vector{LWCPlugin}LWCPlugin[]Additional plugins.
source
lwc_baseline(timestamps::Vector{TimeType}, values::Vector{Real}; kw...) -> LWCChart
lwc_baseline(timestamps::Vector{Real}, values::Vector{Real}; kw...) -> LWCChart

Creates a LWCChart from the passed timestamps and values.

source
lwc_baseline(data::Vector{Tuple{TimeType,Real}}; kw...) -> LWCChart
lwc_baseline(data::Vector{Tuple{Real,Real}}; kw...) -> LWCChart

Creates a LWCChart from the passed data that describes a vector of timestamps and values.

source
lwc_baseline(values::Vector{Real}; kw...) -> LWCChart

Creates a LWCChart from the passed values (timestamps begin from 1970-01-01).

source
lwc_baseline(custom_data::Vector{Any}; kw...) -> LWCChart

Creates a LWCChart from the passed custom_data.

For more information see Custom data section.

source

Example

using LightweightCharts

t_values = round(Int64, time()) .+ collect(1:500)
x_values = map(x -> sin(x / 10) + cos(x / 5), 1:500)

chart = lwc_baseline(
    t_values,
    x_values;
    label_name = "lwc_baseline",
    base_value = LWCBaseValue("price", 0.0),
    line_style = LWC_SOLID,
    line_type = LWC_CURVED,
    line_width = 3,
    precision = 4,
    price_scale_id = LWC_RIGHT,
)

lwc_save("baseline_example.html", chart)

Area

LightweightCharts.Charts.lwc_areaFunction
lwc_area(Vector{LWCSimpleChartItem}; kw...) -> LWCChart

Creates a LWCChart object that contains line chart information. A general method that allows you to customize each chart node using LWCSimpleChartItem.

Wrapper function for Area.

Keyword arguments

Name::TypeDefault (Possible values)Description
price_scale_id::LWC_PRICE_SCALE_IDLWC_LEFT (LWC_RIGHT)Y-axis display side.
label_name::String""Chart name.
visible::BooltrueChart visibility.
precision::Int642Number of decimal places for y-axis values.
top_color::String"rgba(46, 220, 135, 0.4)"Color of the upper part of the area.
bottom_color::String"rgba(40, 221, 100, 0)"Color of the lower part of the area.
invert_filled_area::BoolfalseInverted display of colors.
line_color::StringRandom colorLine color.
line_style::LWC_LINE_STYLESLWC_SOLID (LWC_DOTTED, LWC_DASHED, LWC_LARGE_DASHED, LWC_SPARSE_DOTTED)Line style.
line_width::Int641Line width.
line_type::LWC_LINE_TYPESLWC_SIMPLE (LWC_SIMPLE, LWC_STEP, LWC_CURVED)Line type.
point_markers_visible::BoolfalseDisplaying markers on line nodes.
point_markers_radius::Float644.0Size of markers.
crosshair_marker_visible::BooltrueCursor crosshair visibility.
crosshair_marker_radius::Float644.0Size of crosshair.
crosshair_marker_border_color::String"#758696"Border color of crosshair.
crosshair_marker_background_color::String"#4c525e"Background color of crosshair.
crosshair_marker_border_width::Float642.0Border width of the crosshair.
plugins::Vector{LWCPlugin}LWCPlugin[]Additional plugins.
source
lwc_area(timestamps::Vector{TimeType}, values::Vector{Real}; kw...) -> LWCChart
lwc_area(timestamps::Vector{Real}, values::Vector{Real}; kw...) -> LWCChart

Creates a LWCChart from the passed timestamps and values.

source
lwc_area(data::Vector{Tuple{TimeType,Real}}; kw...) -> LWCChart
lwc_area(data::Vector{Tuple{Real,Real}}; kw...) -> LWCChart

Creates a LWCChart from the passed data that describes a vector of timestamps and values.

source
lwc_area(values::Vector{Real}; kw...) -> LWCChart

Creates a LWCChart from the passed values (timestamps begin from 1970-01-01).

source
lwc_area(custom_data::Vector{Any}; kw...) -> LWCChart

Creates a LWCChart from the passed custom_data.

For more information see Custom data section.

source

Example

using Dates
using LightweightCharts

t_values = round(Int64, time()) .+ collect(1:500)
x_values = map(x -> x % 20, 1:500)

chart = lwc_area(
    t_values,
    x_values;
    label_name = "lwc_area",
    line_color = "#00b4d8",
    top_color = "#90e0ef",
    bottom_color = "rgba(133, 242, 240, 0)",
    line_style = LWC_SOLID,
    line_type = LWC_STEP,
    line_width = 2,
    precision = 3,
    price_scale_id = LWC_RIGHT,
)

lwc_save("area_example.html", chart)

Histogram

LightweightCharts.Charts.lwc_histogramFunction
lwc_histogram(Vector{LWCSimpleChartItem}; kw...) -> LWCChart

Creates a LWCChart object that contains line chart information. A general method that allows you to customize each chart node using LWCSimpleChartItem.

Wrapper function for Histogram.

Keyword arguments

Name::TypeDefault (Possible values)Description
price_scale_id::LWC_PRICE_SCALE_IDLWC_LEFT (LWC_RIGHT)Y-axis display side.
label_name::String""Chart name.
visible::BooltrueChart visibility.
precision::Int642Number of decimal places for y-axis values.
color::StringRandom colorHistogram color.
base::Real0.0The value relative to which the larger or smaller histogram values will be located.
plugins::Vector{LWCPlugin}LWCPlugin[]Additional plugins.
source
lwc_histogram(timestamps::Vector{TimeType}, values::Vector{Real}; kw...) -> LWCChart
lwc_histogram(timestamps::Vector{Real}, values::Vector{Real}; kw...) -> LWCChart

Creates a LWCChart from the passed timestamps and values.

source
lwc_histogram(data::Vector{Tuple{TimeType,Real}}; kw...) -> LWCChart
lwc_histogram(data::Vector{Tuple{Real,Real}}; kw...) -> LWCChart

Creates a LWCChart from the passed data that describes a vector of timestamps and values.

source
lwc_histogram(values::Vector{Real}; kw...) -> LWCChart

Creates a LWCChart from the passed values (timestamps begin from 1970-01-01).

source
lwc_histogram(custom_data::Vector{Any}; kw...) -> LWCChart

Creates a LWCChart from the passed custom_data.

For more information see Custom data section.

source

Example

using LightweightCharts

t_values = round(Int64, time()) .+ collect(1:500)
x_values = map(x -> x * cos(x / 10), 1:500)

chart = lwc_histogram(
    t_values,
    x_values;
    label_name = "lwc_histogram",
    base = 0.0,
    color = "rgba(240, 113, 103, 0.5)",
    price_scale_id = LWC_RIGHT,
)

lwc_save("histogram_example.html", chart)

OHLC Candles

LightweightCharts.ChartData.LWCCandleChartItemType
LWCCandleChartItem(time::Int64, open::Real, high::Real, low::Real, close::Real; kw...)
LWCCandleChartItem(time::TimeType, open::Real, high::Real, low::Real, close::Real; kw...)

Representation of candlestick data for lwc_candlestick and lwc_bar methods.

Fields

  • time::Int64
  • open::Float64
  • high::Float64
  • low::Float64
  • close::Float64

Keyword arguments

Name::TypeDefault (Possible values)Description
color::StringnothingCandle color.
border_color::StringnothingBorder color.
wick_color::StringnothingWick color.
source

Candlestick

LightweightCharts.Charts.lwc_candlestickFunction
lwc_candlestick(data::Vector{LWCCandleChartItem}; kw...) -> LWCChart

Creates a LWCChart object that contains candlesticks chart information. A general method that allows you to customize each chart node using LWCCandleChartItem.

Wrapper function for Candlestick.

Keyword arguments

Name::TypeDefault (Possible values)Description
price_scale_id::LWC_PRICE_SCALE_IDLWC_LEFT (LWC_RIGHT)Y-axis display side.
label_name::String""Chart name.
visible::BooltrueChart visibility.
precision::Int642Number of decimal places for y-axis values.
up_color::String"#26a69a"Color of bullish candle (increasing).
down_color::String"#ef5350"Color of bearish candle (decreasing).
wick_visible::BooltrueWick visibility.
border_visible::BooltrueCandle borders visibility.
border_color::String"#378658"Candle border color.
border_up_color::String"#26a69a"Boder color of bullish candle.
border_down_color::String"#ef5350"Boder color of bearish candle.
wick_color::String"#737375"Wick color.
wick_up_color::String"#26a69a"Wick color of bullish candle.
wick_down_color::String"#ef5350"Wick color of bearish candle.
plugins::Vector{LWCPlugin}LWCPlugin[]Additional plugins.
source
lwc_candlestick(arg...; kw...) -> LWCChart

Creates a LWCChart from the passed arg that describes the corresponding candlestick values.

Arguments

  • timestamps::Vector{Union{Real,TimeType}}
  • open::Vector{Real}
  • high::Vector{Real}
  • low::Vector{Real}
  • close::Vector{Real}
source
lwc_candlestick(data::Vector{Tuple{D,O,H,L,C}}; kw...) -> LWCChart

Creates a LWCChart from the passed data that describes a vector of candles. Here D is a Real or TimeType and O,H,L,C are Reals.

source
lwc_candlestick(custom_data::Vector{Any}; kw...) -> LWCChart

Creates a LWCChart from the passed custom_data.

For more information see Custom data section.

source

Example

using Dates
using LightweightCharts

open_time = now() .+ Second.(1:500)
x_values = map(x -> sin(2rand() + x / 10), 1:500)

chart = lwc_candlestick(
    LWCCandleChartItem.(
        open_time,
        x_values,
        x_values .+ rand(500),
        x_values .- rand(500),
        [x_values[2:end]..., x_values[begin]],
    );
    label_name = "lwc_candlestick",
    up_color = "#52a49a",
    down_color = "#de5e57",
    border_visible = false,
    price_scale_id = LWC_RIGHT,
)

lwc_save("candlestick_example.html", chart)

Bar

LightweightCharts.Charts.lwc_barFunction
lwc_bar(data::Vector{LWCCandleChartItem}; kw...) -> LWCChart

Creates a LWCChart object that contains bar chart information. A general method that allows you to customize each chart node using LWCCandleChartItem.

Wrapper function for Bar.

Keyword arguments

Name::TypeDefault (Possible values)Description
price_scale_id::LWC_PRICE_SCALE_IDLWC_LEFT (LWC_RIGHT)Y-axis display side.
label_name::String""Chart name.
visible::BooltrueChart visibility.
precision::Int642Number of decimal places for y-axis values.
up_color::String"#26a69a"Color of bullish candle (increasing).
down_color::String"#ef5350"Color of bearish candle (decreasing).
open_visible::BooltrueOpen tick visibility.
thin_bars::BooltrueThin bars.
plugins::Vector{LWCPlugin}LWCPlugin[]Additional plugins.
source
lwc_bar(arg...; kw...) -> LWCChart

Creates a LWCChart from the passed arg that describes the corresponding candlestick values.

Arguments

  • timestamps::Vector{Union{Real,TimeType}}
  • open::Vector{Real}
  • high::Vector{Real}
  • low::Vector{Real}
  • close::Vector{Real}
source
lwc_bar(data::Vector{Tuple{D,O,H,L,C}}; kw...) -> LWCChart

Creates a LWCChart from the passed data that describes a vector of candles. Here D is a Real or TimeType and O,H,L,C are Reals.

source
lwc_bar(custom_data::Vector{Any}; kw...) -> LWCChart

Creates a LWCChart from the passed custom_data.

For more information see Custom data section.

source

Example

using Dates
using LightweightCharts

open_time = now() .+ Second.(1:500)
x_values = map(x -> sin(2rand() + x / 10), 1:500)

chart = lwc_bar(
    LWCCandleChartItem.(
        open_time,
        x_values,
        x_values .+ rand(500),
        x_values .- rand(500),
        [x_values[2:end]..., x_values[begin]],
    );
    label_name = "lwc_bar",
    up_color = "#52a49a",
    down_color = "#de5e57",
    price_scale_id = LWC_RIGHT,
)

lwc_save("bar_example.html", chart)

Multi-colors

LightweightCharts.ChartData.LWCSimpleChartItemType
LWCSimpleChartItem(time::Int64, value::Real; kw...)
LWCSimpleChartItem(time::TimeType, value::Real; kw...)

This data type allows you to customize the colors for each point of your chart. Supported for lwc_line, lwc_area, lwc_baseline and lwc_histogram methods.

Fields

  • time::Int64: Data unix time.
  • value::Float64: Data value.

Keyword arguments

Name::TypeDefault (Possible values)Description
line_color::StringnothingLine color.
top_color::StringnothingTop color.
bottom_color::StringnothingBottom color.
top_fill_color_1::StringnothingTop fill color 1.
top_fill_color_2::StringnothingTop fill color 2.
top_line_color::StringnothingTop line color.
bottom_fill_color_1::StringnothingBottom fill color 1.
bottom_fill_color_2::StringnothingBottom fill color 2.
bottom_line_color::StringnothingBottom line color.
color::StringnothingColor.
source

Example

using Dates
using LightweightCharts
import LightweightCharts: randcolor

t_range = 1:500

chart = lwc_baseline(
    map(
        x -> LWCSimpleChartItem(
            now() + Second(x),
            cos.(x / 10);
            color = randcolor(),
            top_line_color = randcolor(),
            top_fill_color_1 = randcolor(),
            bottom_line_color = randcolor(),
            bottom_fill_color_2 = randcolor(),
        ),
        t_range,
    );
    label_name = "lwc_baseline",
    line_type = LWC_STEP,
    price_scale_id = LWC_RIGHT,
    line_width = 4,
)

lwc_save("colors_example.html", chart)

Custom data

Vectors with custom data types can also be visualized.

The simplest way to add visualization support to your custom type is to define a new conversion method from CustomType to Tuple with the following signature:

For simple charts (e.g lwc_line, lwc_area, ...)

Base.convert(::Type{Tuple}, x::CustomType)::Tuple{TimeType,Real} = ...
# OR
Base.convert(::Type{Tuple}, x::CustomType)::Tuple{Real,Real} = ...

For candle charts (e.g lwc_candlestick, lwc_bar)

Base.convert(::Type{Tuple}, x::CustomType)::Tuple{TimeType,Real,Real,Real,Real} = ...
# OR
Base.convert(::Type{Tuple}, x::CustomType)::Tuple{Real,Real,Real,Real,Real} = ...

If such a conversion method is already defined for other purposes, then you can define another conversion methods that allows you to create objects LWCSimpleChartItem or LWCCandleChartItem (this method provides more flexible customization options).

Base.convert(::Type{LWCSimpleChartItem}, x::CustomType) = LWCSimpleChartItem(...)
# OR / AND
Base.convert(::Type{LWCCandleChartItem}, x::CustomType) = LWCCandleChartItem(...)

Examples

using Dates
using LightweightCharts

struct Point
    timestamp::DateTime
    value::Float64
end

Base.convert(::Type{Tuple}, x::Point) = (x.timestamp, x.value)
# OR
function Base.convert(::Type{LWCSimpleChartItem}, x::Point)
    return LWCSimpleChartItem(x.timestamp, x.value)
end

points = [Point(now() + Second(x), sin(x / 10.0)) for x in 1:500]

chart = lwc_line(
    points;
    label_name = "custom points",
    line_color = "#a8dadc",
    line_width = 3,
)

lwc_save("custom_simple_type_example.html", chart)
using Dates
using LightweightCharts

struct OHLC
    timestamp::DateTime
    open::Float64
    high::Float64
    low::Float64
    close::Float64
end

Base.convert(::Type{Tuple}, x::OHLC) = (x.timestamp, x.open, x.high, x.low, x.close)
# OR
function Base.convert(::Type{LWCCandleChartItem}, x::OHLC)
    return LWCCandleChartItem(x.timestamp, x.open, x.high, x.low, x.close)
end

candles = [OHLC(now() + Second(x), rand(), rand(), rand(), rand()) for x in 1:500]

chart = lwc_candlestick(
    candles;
    label_name = "custom candles",
)

lwc_save("custom_candle_type_example.html", chart)