Charts
LightweightCharts.LWCChart
— TypeLWCChart
The base type that contains the necessary information for visualizing a single chart (and its plugins
).
Line
LightweightCharts.Charts.lwc_line
— Functionlwc_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::Type | Default (Possible values) | Description |
---|---|---|
price_scale_id::LWC_PRICE_SCALE_ID | LWC_LEFT (LWC_RIGHT ) | Y-axis display side. |
label_name::String | "" | Chart name. |
visible::Bool | true | Chart visibility. |
precision::Int64 | 2 | Number of decimal places for y-axis values. |
line_color::String | Random color | Line color. |
line_style::LWC_LINE_STYLES | LWC_SOLID (LWC_DOTTED , LWC_DASHED , LWC_LARGE_DASHED , LWC_SPARSE_DOTTED ) | Line style. |
line_width::Int64 | 1 | Line width. |
line_type::LWC_LINE_TYPES | LWC_SIMPLE (LWC_STEP , LWC_CURVED ) | Line type. |
line_visible::Bool | true | Line visibility. |
point_markers_visible::Bool | false | Displaying markers on line nodes. |
point_markers_radius::Float64 | 4.0 | Size of markers. |
crosshair_marker_visible::Bool | true | Cursor crosshair visibility. |
crosshair_marker_radius::Float64 | 4.0 | Size 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::Float64 | 2.0 | Border width of the crosshair. |
plugins::Vector{LWCPlugin} | LWCPlugin[] | Additional plugins. |
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
.
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.
lwc_line(values::Vector{Real}; kw...) -> LWCChart
Creates a LWCChart
from the passed values
(timestamps begin from 1970-01-01
).
lwc_line(custom_data::Vector{Any}; kw...) -> LWCChart
Creates a LWCChart
from the passed custom_data
.
For more information see Custom data section.
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_baseline
— Functionlwc_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::Type | Default (Possible values) | Description |
---|---|---|
price_scale_id::LWC_PRICE_SCALE_ID | LWC_LEFT (LWC_RIGHT ) | Y-axis display side. |
label_name::String | "" | Chart name. |
visible::Bool | true | Chart visibility. |
precision::Int64 | 2 | Number of decimal places for y-axis values. |
base_value::LWCBaseValue | LWCBaseValue("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::Int64 | 1 | Line width. |
line_style::LWC_LINE_STYLES | LWC_SOLID (LWC_DOTTED , LWC_DASHED , LWC_LARGE_DASHED , LWC_SPARSE_DOTTED ) | Line style. |
line_type::LWC_LINE_TYPES | LWC_SIMPLE (LWC_STEP , LWC_CURVED ) | Line type. |
line_visible::Bool | true | Line visibility. |
point_markers_visible::Bool | false | Displaying markers on line nodes. |
point_markers_radius::Float64 | 4.0 | Size of markers. |
crosshair_marker_visible::Bool | true | Cursor crosshair visibility. |
crosshair_marker_radius::Float64 | 4.0 | Size 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::Float64 | 2.0 | Border width of the crosshair. |
plugins::Vector{LWCPlugin} | LWCPlugin[] | Additional plugins. |
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
.
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.
lwc_baseline(values::Vector{Real}; kw...) -> LWCChart
Creates a LWCChart
from the passed values
(timestamps begin from 1970-01-01
).
lwc_baseline(custom_data::Vector{Any}; kw...) -> LWCChart
Creates a LWCChart
from the passed custom_data
.
For more information see Custom data section.
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_area
— Functionlwc_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::Type | Default (Possible values) | Description |
---|---|---|
price_scale_id::LWC_PRICE_SCALE_ID | LWC_LEFT (LWC_RIGHT ) | Y-axis display side. |
label_name::String | "" | Chart name. |
visible::Bool | true | Chart visibility. |
precision::Int64 | 2 | Number 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::Bool | false | Inverted display of colors. |
line_color::String | Random color | Line color. |
line_style::LWC_LINE_STYLES | LWC_SOLID (LWC_DOTTED , LWC_DASHED , LWC_LARGE_DASHED , LWC_SPARSE_DOTTED ) | Line style. |
line_width::Int64 | 1 | Line width. |
line_type::LWC_LINE_TYPES | LWC_SIMPLE (LWC_SIMPLE , LWC_STEP , LWC_CURVED ) | Line type. |
point_markers_visible::Bool | false | Displaying markers on line nodes. |
point_markers_radius::Float64 | 4.0 | Size of markers. |
crosshair_marker_visible::Bool | true | Cursor crosshair visibility. |
crosshair_marker_radius::Float64 | 4.0 | Size 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::Float64 | 2.0 | Border width of the crosshair. |
plugins::Vector{LWCPlugin} | LWCPlugin[] | Additional plugins. |
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
.
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.
lwc_area(values::Vector{Real}; kw...) -> LWCChart
Creates a LWCChart
from the passed values
(timestamps begin from 1970-01-01
).
lwc_area(custom_data::Vector{Any}; kw...) -> LWCChart
Creates a LWCChart
from the passed custom_data
.
For more information see Custom data section.
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_histogram
— Functionlwc_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::Type | Default (Possible values) | Description |
---|---|---|
price_scale_id::LWC_PRICE_SCALE_ID | LWC_LEFT (LWC_RIGHT ) | Y-axis display side. |
label_name::String | "" | Chart name. |
visible::Bool | true | Chart visibility. |
precision::Int64 | 2 | Number of decimal places for y-axis values. |
color::String | Random color | Histogram color. |
base::Real | 0.0 | The value relative to which the larger or smaller histogram values will be located. |
plugins::Vector{LWCPlugin} | LWCPlugin[] | Additional plugins. |
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
.
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.
lwc_histogram(values::Vector{Real}; kw...) -> LWCChart
Creates a LWCChart
from the passed values
(timestamps begin from 1970-01-01
).
lwc_histogram(custom_data::Vector{Any}; kw...) -> LWCChart
Creates a LWCChart
from the passed custom_data
.
For more information see Custom data section.
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.LWCCandleChartItem
— TypeLWCCandleChartItem(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::Type | Default (Possible values) | Description |
---|---|---|
color::String | nothing | Candle color. |
border_color::String | nothing | Border color. |
wick_color::String | nothing | Wick color. |
Candlestick
LightweightCharts.Charts.lwc_candlestick
— Functionlwc_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::Type | Default (Possible values) | Description |
---|---|---|
price_scale_id::LWC_PRICE_SCALE_ID | LWC_LEFT (LWC_RIGHT ) | Y-axis display side. |
label_name::String | "" | Chart name. |
visible::Bool | true | Chart visibility. |
precision::Int64 | 2 | Number 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::Bool | true | Wick visibility. |
border_visible::Bool | true | Candle 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. |
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}
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 Real
s.
lwc_candlestick(custom_data::Vector{Any}; kw...) -> LWCChart
Creates a LWCChart
from the passed custom_data
.
For more information see Custom data section.
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_bar
— Functionlwc_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::Type | Default (Possible values) | Description |
---|---|---|
price_scale_id::LWC_PRICE_SCALE_ID | LWC_LEFT (LWC_RIGHT ) | Y-axis display side. |
label_name::String | "" | Chart name. |
visible::Bool | true | Chart visibility. |
precision::Int64 | 2 | Number 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::Bool | true | Open tick visibility. |
thin_bars::Bool | true | Thin bars. |
plugins::Vector{LWCPlugin} | LWCPlugin[] | Additional plugins. |
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}
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 Real
s.
lwc_bar(custom_data::Vector{Any}; kw...) -> LWCChart
Creates a LWCChart
from the passed custom_data
.
For more information see Custom data section.
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.LWCSimpleChartItem
— TypeLWCSimpleChartItem(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::Type | Default (Possible values) | Description |
---|---|---|
line_color::String | nothing | Line color. |
top_color::String | nothing | Top color. |
bottom_color::String | nothing | Bottom color. |
top_fill_color_1::String | nothing | Top fill color 1. |
top_fill_color_2::String | nothing | Top fill color 2. |
top_line_color::String | nothing | Top line color. |
bottom_fill_color_1::String | nothing | Bottom fill color 1. |
bottom_fill_color_2::String | nothing | Bottom fill color 2. |
bottom_line_color::String | nothing | Bottom line color. |
color::String | nothing | Color. |
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)