### Configure Volume Scale Margins and Colors Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Adjust the volume configuration by setting the top and bottom scale margins, as well as the up and down colors for the volume bars. Note that margin values must be between 0 and 1. ```python volume_config(_scale_margin_top : float_, _scale_margin_bottom : float_, _up_color : COLOR_, _down_color : COLOR_) ``` -------------------------------- ### Create Table Element Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Create and return a `Table` object with specified dimensions, headings, column widths, alignments, position, and interactivity options. It can also return clicked cell information. ```python create_table(_width : NUM_, _height : NUM_, _headings : Tuple[str]_, _widths : Tuple[float]_, _alignments : Tuple[str]_, _position : FLOAT_, _draggable : bool_, _return_clicked_cells : bool_, _func : callable_) → Table ``` -------------------------------- ### Configure Chart Layout and Appearance Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Set global layout options including background color, text color, font size, and font family for the chart. This affects the overall visual presentation of the chart elements. ```python layout(_background_color : COLOR_, _text_color : COLOR_, _font_size : int_, _font_family : str_) ``` -------------------------------- ### Python Table Class Initialization and Methods Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/tables Demonstrates the initialization of the Table class and its core methods for managing rows, formatting columns, and controlling visibility. This includes creating new rows, clearing the table, applying custom formats to columns, and toggling table visibility. ```python table = create_table( width=0.5, height=100, headings=('Symbol', 'Price', 'Change'), widths=(0.3, 0.4, 0.3), alignments=('left', 'right', 'right'), position=0.1, draggable=True, return_clicked_cells=True, func=on_row_click ) # Add a new row row_id = table.new_row('AAPL', 150.0, -1.5) # Format a column table.format('Price', f'{table.VALUE:.2f}') # Toggle visibility table.visible(True) # Clear all rows table.clear() ``` -------------------------------- ### Configure Time Scale Options Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Set options for the chart's time scale, such as right offset, minimum bar spacing, visibility of the time scale and seconds, and border visibility and color. ```python time_scale(_right_offset : int_, _min_bar_spacing : float_, _visible : bool_, _time_visible : bool_, _seconds_visible : bool_, _border_visible : bool_, _border_color : COLOR_) ``` -------------------------------- ### Configure Price Scale Options Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Set various options for the chart's price scale, including auto-scaling, mode, inversion, label alignment, margins, border visibility and color, text color, and tick visibility. ```python price_scale(_auto_scale : bool_, _mode : PRICE_SCALE_MODE_, _invert_scale : bool_, _align_labels : bool_, _scale_margin_top : float_, _scale_margin_bottom : float_, _border_visible : bool_, _border_color : COLOR_, _text_color : COLOR_, _entire_text_only : bool_, _visible : bool_, _ticks_visible : bool_, _minimum_width : float_) ``` -------------------------------- ### QtChart Integration - Python Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/charts The QtChart object integrates lightweight-charts into a QMainWindow using PyQt5, PyQt6, or PySide6. It provides similar data manipulation and styling features as the Chart object and allows access to the underlying QWebEngineView. ```python from PyQt5.QtWidgets import QMainWindow, QApplication from lightweight_charts.charts import QtChart # Assume app and main_window are initialized # app = QApplication([]) # main_window = QMainWindow() # Initialize QtChart with a QWidget parent # qt_chart = QtChart(main_window) # Get the underlying QWebEngineView object # webview = qt_chart.get_webview() ``` -------------------------------- ### Line Object Methods Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/line This section details the methods available for the Line object, which represents a LineSeries in Lightweight Charts. ```APIDOC ## `Line` Class ### Description Represents a `LineSeries` object in Lightweight Charts, used for creating indicators. Access its instance only from `create_line`. ### Method `__init__` ### Parameters - **name** (str) - The name of the line series. - **color** (COLOR) - The color of the line. - **style** (LINE_STYLE) - The style of the line (e.g., solid, dashed). - **width** (int) - The width of the line. - **price_line** (bool) - Whether to display a price line. - **price_label** (bool) - Whether to display a price label. - **price_scale_id** (str) - The ID of the price scale to use. --- ## `Line.set()` ### Description Sets the data for the line series. If no name is set during initialization, columns should be named `time | value`. Otherwise, it uses the column named after the provided `name`. ### Method `set` ### Parameters #### Request Body - **data** (pd.DataFrame) - A pandas DataFrame containing the time series data. ### Request Example ```python import pandas as pd data = pd.DataFrame({ 'time': pd.to_datetime(['2024-01-01', '2024-01-02', '2024-01-03']), 'value': [10, 12, 15] }) line.set(data) ``` ### Response #### Success Response (200) No explicit response body is defined for this method. Operation is usually confirmed by observing the chart update. --- ## `Line.update()` ### Description Updates the data for the line series with new data. ### Method `update` ### Parameters #### Request Body - **series** (pd.Series) - A pandas Series object with labels corresponding to the line's data format. ### Request Example ```python import pandas as pd new_data = pd.Series({ 'time': pd.to_datetime('2024-01-04'), 'value': 17 }) line.update(new_data) ``` ### Response #### Success Response (200) No explicit response body is defined for this method. Operation is usually confirmed by observing the chart update. --- ## `Line.delete()` ### Description Irreversibly deletes the line series from the chart. ### Method `delete` ### Request Example ```python line.delete() ``` ### Response #### Success Response (200) No explicit response body is defined for this method. Operation is usually confirmed by observing the chart update. * * * Next: `Histogram` Previous: `AbstractChart` ``` -------------------------------- ### AbstractChart Initialization Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Initializes an AbstractChart object. This is the base class for creating specific chart types. ```APIDOC ## AbstractChart ### Description Abstracted chart used to create child classes. ### Method __init__ ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **width** (float) - The width of the chart. * **height** (float) - The height of the chart. ``` -------------------------------- ### Display Loading Spinner Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Show a loading spinner on the chart to indicate data loading or API calls. This method should be used in conjunction with the search event for proper synchronization. ```python spinner(_visible : bool_) ``` -------------------------------- ### Control Price Line Visibility Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Configure the visibility of the last value price line and its associated label. Options include controlling the line visibility and label visibility. ```python price_line(_label_visible : bool_, _line_visible : bool_, _title : str_) ``` -------------------------------- ### AbstractChart Methods Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart This section details the various methods available on the AbstractChart class for managing and customizing charts. ```APIDOC ## AbstractChart Class Methods ### Description Methods for interacting with and customizing charts created using the AbstractChart class. ### Methods - `set()` - `update()` - `update_from_tick()` - `create_line()` - `create_histogram()` - `lines()` - `trend_line()` - `ray_line()` - `vertical_span()` - `set_visible_range()` - `resize()` - `marker()` - `marker_list()` - `remove_marker()` - `horizontal_line()` - `clear_markers()` - `precision()` - `price_scale()` - `time_scale()` - `layout()` - `grid()` - `candle_style()` - `volume_config()` - `crosshair()` - `watermark()` - `legend()` - `spinner()` - `price_line()` - `fit()` - `show_data()` - `hide_data()` - `hotkey()` - `create_table()` - `create_subchart()` ### Parameters (Specific parameters for each method are not detailed in the provided text, but would typically include data, style options, etc.) ### Request Example (No specific request examples provided for individual methods in the text.) ### Response (Response details for each method are not provided in the text.) ``` -------------------------------- ### Initialize ToolBox and Save Drawings (Python) Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/toolbox Demonstrates how to enable the ToolBox by setting the 'toolbox' parameter to True during Chart initialization and how to save drawings to a topbar widget. The ToolBox allows drawing and editing trendlines, ray lines, and horizontal lines. ```python chart = Chart(toolbox=True) chart.toolbox.save_drawings_under(chart.topbar['symbol']) ``` -------------------------------- ### Chart Class Initialization and Methods - Python Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/charts The main Chart object for lightweight-charts-python, built on pywebview. It requires an `if __name__ == '__main__'` block for definition. Methods include showing the chart (blocking or asynchronously), hiding it, exiting the window, and taking screenshots. ```python from lightweight_charts.charts import Chart import pandas as pd # Chart object initialization requires specific parameters # Example: chart = Chart(_width=800, _height=600, _title='My Chart') # Define chart within an if __name__ == '__main__' block if __name__ == '__main__': chart = Chart() df = pd.read_csv('ohlcv.csv') chart.set(df) # Show the chart window (blocking) chart.show(_block=True) # Hide the chart window chart.hide() # Exit and destroy the chart window chart.exit() # Show the chart asynchronously # chart.show_async() # Take a screenshot (blocking) img = chart.screenshot(_block=True) with open('screenshot.png', 'wb') as f: f.write(img) ``` -------------------------------- ### Subscribe to Chart Events in Python Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/events Demonstrates how to subscribe to chart events using the `chart.events. += ` syntax in Python. This allows for asynchronous and synchronous callbacks when specific chart actions occur. ```python class Chart: # ... other chart methods ... events: Events class Events: def __init__(self): self._listeners = {} def __getattr__(self, name): if name not in self._listeners: self._listeners[name] = [] return lambda callback: self._listeners[name].append(callback) def trigger(self, event_name, *args, **kwargs): if event_name in self._listeners: for callback in self._listeners[event_name]: callback(*args, **kwargs) # Example Usage: def handle_new_bar(chart): print("New bar added to the chart!") def handle_click(chart, time, price): print(f"Chart clicked at time: {time}, price: {price}") # Assuming 'my_chart' is an instance of Chart # my_chart.events.new_bar += handle_new_bar # my_chart.events.click += handle_click # To simulate an event: # my_chart.events.trigger('new_bar', my_chart) # my_chart.events.trigger('click', my_chart, 1678886400, 150.5) ``` -------------------------------- ### Data Management Methods Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Methods for setting, updating, and managing chart data. ```APIDOC ## `set` Method ### Description Sets the initial data for the chart. Supports pandas DataFrame with specific columns or None to clear data. Can also handle custom candle colors. ### Method set ### Endpoint Not applicable (method of an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **data** (pd.DataFrame | None) - The data to set. Expected columns: `time` (or `date`), `open`, `high`, `low`, `close`, `volume`. Volume is optional. Time can be in the index. `None` clears data. * **keep_drawings** (bool) - Optional. If True, existing drawings are preserved. Defaults to False. ``` ```APIDOC ## `update` Method ### Description Updates the chart data from a single bar represented by a pandas Series. ### Method update ### Endpoint Not applicable (method of an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **series** (pd.Series) - A pandas Series containing bar data. Labels should match `set` method requirements. * **keep_drawings** (bool) - Optional. If True, existing drawings are preserved. Defaults to False. ``` ```APIDOC ## `update_from_tick` Method ### Description Updates the chart data from a single tick. Handles automatic interval rounding. ### Method update_from_tick ### Endpoint Not applicable (method of an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **series** (pd.Series) - A pandas Series containing tick data. Expected labels: `time` (or `date`), `price`, `volume`. Volume is optional. Time can be the Series name. * **cumulative_volume** (bool) - Optional. If True, volume is added to the latest bar. Defaults to False. ``` -------------------------------- ### Create Subchart Panel Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Create and return a new Chart object (subchart) adjacent to the current chart. Allows for multiple chart panels within the same window, with options for positioning, sizing, and syncing with other charts. ```python create_subchart(_position : FLOAT_, _width : float_, _height : float_, _sync : bool | str_, _sync_crosshairs_only : bool_, _scale_candles_only : bool_, _toolbox : bool_) → AbstractChart ``` -------------------------------- ### Type Aliases and Definitions Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/typing This section details the various type aliases and classes used throughout the Lightweight Charts Python library to define expected data types for parameters and return values. ```APIDOC ## Type Definitions ### Description These classes and type aliases serve as placeholders and definitions for type requirements within the Lightweight Charts Python library. They specify the expected data types for various parameters, ensuring type safety and clarity. ### `NUM` - **Type**: `Literal[float, int]` - **Description**: Represents a numerical value, which can be either a floating-point number or an integer. ### `FLOAT` - **Type**: `Literal['left', 'right', 'top', 'bottom']` - **Description**: This type alias seems to be mislabeled in the original documentation. Based on its possible usage in layout or alignment contexts, it appears to represent directional literals, not float numbers. The provided literals suggest it might be used for positioning or alignment. ### `TIME` - **Type**: `Union[datetime, pd.Timestamp, str]` - **Description**: Represents a time value, which can be provided as a Python `datetime` object, a `pandas.Timestamp`, or a string representation of a date/time. ### `COLOR` - **Type**: `str` - **Description**: Represents a color value. Colors can be specified in several formats: `rgb(R, G, B)`, `rgba(R, G, B, A)`, hex codes (e.g., `#RRGGBB`), or standard HTML color names (e.g., 'blue', 'red'). ### `LINE_STYLE` - **Type**: `Literal['solid', 'dotted', 'dashed', 'large_dashed', 'sparse_dotted']` - **Description**: Defines the style for chart lines. Allowed values include 'solid', 'dotted', 'dashed', 'large_dashed', and 'sparse_dotted'. ### `MARKER_POSITION` - **Type**: `Literal['above', 'below', 'inside']` - **Description**: Specifies the position of markers relative to data points. Valid options are 'above', 'below', or 'inside' the data point. ### `MARKER_SHAPE` - **Type**: `Literal['arrow_up', 'arrow_down', 'circle', 'square']` - **Description**: Defines the shape of markers used on the chart. Supported shapes include 'arrow_up', 'arrow_down', 'circle', and 'square'. ### `CROSSHAIR_MODE` - **Type**: `Literal['normal', 'magnet']` - **Description**: Controls the behavior of the crosshair tool. Modes are 'normal' (standard crosshair) or 'magnet' (crosshair snaps to data points). ### `PRICE_SCALE_MODE` - **Type**: `Literal['normal', 'logarithmic', 'percentage', 'index100']` - **Description**: Determines how the price scale is displayed. Options include 'normal' (linear scale), 'logarithmic', 'percentage', and 'index100' (sets the first data point to 100%). ### `ALIGN` - **Type**: `Literal['left', 'right']` - **Description**: Specifies the alignment, typically for text or elements within the chart. Allowed values are 'left' or 'right'. ``` -------------------------------- ### WxChart Integration - Python Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/charts The WxChart object integrates lightweight-charts into a wx.Frame using wxPython. It offers comparable functionality to the Chart object for data handling and styling, and provides access to the wx.html2.WebView object for positioning and styling. ```python import wx from lightweight_charts.charts import WxChart # Assume app and frame are initialized # app = wx.App() # frame = wx.Frame(None, title='WxChart Example') # Initialize WxChart with a WxPanel parent # wx_chart = WxChart(frame) # Get the underlying wx.html2.WebView object # webview = wx_chart.get_webview() ``` -------------------------------- ### Chart Element Creation Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Methods for creating various graphical elements on the chart. ```APIDOC ## `create_line` Method ### Description Creates and returns a Line object, representing a `LineSeries` for indicators. ### Method create_line ### Endpoint Not applicable (method of an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **name** (str) - The name of the line series. * **color** (COLOR) - The color of the line. * **style** (LINE_STYLE) - The style of the line (e.g., solid, dashed). * **width** (int) - The width of the line. * **price_line** (bool) - Whether to display a price line. * **price_label** (bool) - Whether to display a price label. ``` ```APIDOC ## `create_histogram` Method ### Description Creates and returns a Histogram object, representing a `HistogramSeries` for indicators. ### Method create_histogram ### Endpoint Not applicable (method of an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **name** (str) - The name of the histogram series. * **color** (COLOR) - The color of the histogram bars. * **price_line** (bool) - Whether to display a price line. * **price_label** (bool) - Whether to display a price label. * **scale_margin_top** (float) - Top margin for the scale. * **scale_margin_bottom** (float) - Bottom margin for the scale. ``` ```APIDOC ## `trend_line` Method ### Description Creates a trend line drawn between two specified time-value points. ### Method trend_line ### Endpoint Not applicable (method of an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **start_time** (str | datetime) - The start time of the trend line. * **start_value** (NUM) - The start value of the trend line. * **end_time** (str | datetime) - The end time of the trend line. * **end_value** (NUM) - The end value of the trend line. * **color** (COLOR) - The color of the trend line. * **width** (int) - The width of the trend line. * **style** (LINE_STYLE) - The style of the trend line. * **round** (bool) - Whether to round the line endpoints. ``` ```APIDOC ## `ray_line` Method ### Description Creates a ray line starting from a specified point and extending indefinitely. ### Method ray_line ### Endpoint Not applicable (method of an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **start_time** (str | datetime) - The start time of the ray line. * **value** (NUM) - The value at the start time. * **color** (COLOR) - The color of the ray line. * **width** (int) - The width of the ray line. * **style** (LINE_STYLE) - The style of the ray line. * **round** (bool) - Whether to round the line endpoints. ``` ```APIDOC ## `vertical_span` Method ### Description Creates and returns a `VerticalSpan` object, which can represent a single vertical line or a span between two times. ### Method vertical_span ### Endpoint Not applicable (method of an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **start_time** (TIME | list | tuple) - The start time or a list/tuple of times for vertical lines. * **end_time** (TIME) - Optional. The end time for a vertical span. If not provided, a single vertical line is drawn at `start_time`. * **color** (COLOR) - Optional. The color of the vertical span. Defaults to 'rgba(252, 219, 3, 0.2)'. * **round** (bool) - Optional. Whether to round the time values. Defaults to False. ``` ```APIDOC ## `marker` Method ### Description Adds a marker to the chart at a specified time and returns its ID. Handles placement at the latest bar if time is omitted. ### Method marker ### Endpoint Not applicable (method of an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **time** (datetime) - Optional. The time for the marker. Defaults to the latest bar. * **position** (MARKER_POSITION) - The position of the marker. * **shape** (MARKER_SHAPE) - The shape of the marker. * **color** (COLOR) - The color of the marker. * **text** (str) - The text associated with the marker. ``` ```APIDOC ## `marker_list` Method ### Description Creates multiple markers on the chart and returns a list of their IDs. ### Method marker_list ### Endpoint Not applicable (method of an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **markers** (list) - A list of marker objects to be added to the chart. ``` ```APIDOC ## `horizontal_line` Method ### Description Places a horizontal line on the chart at a specified price and returns a `HorizontalLine` object. ### Method horizontal_line ### Endpoint Not applicable (method of an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **price** (NUM) - The price level for the horizontal line. * **color** (COLOR) - The color of the line. * **width** (int) - The width of the line. * **style** (LINE_STYLE) - The style of the line. * **text** (str) - Text to display with the line. * **axis_label_visible** (bool) - Whether the axis label should be visible. * **func** (callable) - Optional. A callable function associated with the line. ``` -------------------------------- ### Chart Interaction and Display Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Methods for interacting with and controlling the chart's display. ```APIDOC ## `lines` Method ### Description Returns a list of all line series currently present on the chart. ### Method lines ### Endpoint Not applicable (method of an object) ### Parameters None ``` ```APIDOC ## `remove_marker` Method ### Description Removes a specific marker from the chart using its ID. ### Method remove_marker ### Endpoint Not applicable (method of an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **marker_id** (str) - The ID of the marker to remove. ``` ```APIDOC ## `set_visible_range` Method ### Description Sets the currently visible time range of the chart. ### Method set_visible_range ### Endpoint Not applicable (method of an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **start_time** (TIME) - The start time of the visible range. * **end_time** (TIME) - The end time of the visible range. ``` ```APIDOC ## `resize` Method ### Description Resizes the chart within its container. Dimensions are relative (0 to 1). ### Method resize ### Endpoint Not applicable (method of an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **width** (float) - Optional. The new width of the chart (0 to 1). * **height** (float) - Optional. The new height of the chart (0 to 1). If only one dimension is provided, the other remains unchanged. ``` -------------------------------- ### Python Table Footer Initialization and Manipulation Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/tables Illustrates how to initialize and manipulate the footer of a Lightweight Charts Python table. This allows for the creation of text boxes within the footer, which can be updated or converted into clickable buttons. ```python # Initialize footer with 3 text boxes table.footer(3) # Update footer text boxes table.footer[0] = 'Total Value' table.footer[1] = '$ 10,000' table.footer[2] = 'Change: -5.0%' # Initialize footer with clickable buttons def on_footer_click(table, box_index): print(f'Footer box {box_index + 1} clicked.') table.footer(2, func=on_footer_click) table.footer[0] = 'Action 1' table.footer[1] = 'Action 2' ``` -------------------------------- ### Add Global Hotkey Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Register a global hotkey for the chart window that triggers a specified function or method. Supports modifier keys (Ctrl, Alt, Shift, Meta) and can handle multiple keys for the same function using a tuple. ```python hotkey(_modifier : 'ctrl' | 'alt' | 'shift' | 'meta' | None_, _key : 'str' | 'int' | 'tuple'_, _func : callable_) ``` -------------------------------- ### TopBar Widget Management in Python Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/topbar Demonstrates how to declare, access, and modify widgets within the TopBar of a Lightweight Chart using Python. It shows the creation of a textbox, retrieving its value, and updating its content. The `topbar` attribute of the chart object is used to interact with these widgets. ```python chart.topbar.textbox('symbol', 'AAPL') print(chart.topbar['symbol'].value) chart.topbar['symbol'].set('MSFT') print(chart.topbar['symbol'].value) ``` -------------------------------- ### Histogram Class Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/histogram Represents a HistogramSeries object in Lightweight Charts. Used for creating indicators. Instance should be accessed from `create_histogram`. ```APIDOC ## `Histogram` Class ### Description The `Histogram` object represents a `HistogramSeries` object in Lightweight Charts and can be used to create indicators. As well as the methods described below, the `Line` object also has access to: `horizontal_line`, `hide_data`, `show_data` and `price_line`. Its instance should only be accessed from `create_histogram`. ### Constructor `Histogram(_name : str, _color : COLOR, _style : LINE_STYLE, _width : int, _price_line : bool, _price_label : bool_)` ### Methods #### `set(_data : pd.DataFrame_)` ##### Description Sets the data for the histogram. When a name has not been set upon declaration, the columns should be named: `time | value` (Not case sensitive). The column containing the data should be named after the string given in the `name`. A `color` column can be used within the dataframe to specify the color of individual bars. ##### Method `set` ##### Parameters - **`data`** (pd.DataFrame) - Required - The data for the histogram. ##### Request Example ```python # Assuming 'df' is a pandas DataFrame with columns 'time' and 'value' histogram.set(df) ``` #### `update(_series : pd.Series_)` ##### Description Updates the data for the histogram. This should be given as a Series object, with labels akin to the `histogram.set` method. ##### Method `update` ##### Parameters - **`series`** (pd.Series) - Required - The series object containing updated data. ##### Request Example ```python # Assuming 'series_data' is a pandas Series histogram.update(series_data) ``` #### `scale(_scale_margin_top : float, _scale_margin_bottom : float_)` ##### Description Scales the margins of the histogram, as used within `volume_config`. ##### Method `scale` ##### Parameters - **`scale_margin_top`** (float) - Required - The top margin for scaling. - **`scale_margin_bottom`** (float) - Required - The bottom margin for scaling. ##### Request Example ```python histogram.scale(0.1, 0.1) ``` #### `delete()` ##### Description Irreversibly deletes the histogram. ##### Method `delete` ##### Request Example ```python histogram.delete() ``` ``` -------------------------------- ### Load Drawings from Tag (Python) Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/toolbox This method loads and displays drawings that were previously saved under a specific tag. It's part of the ToolBox functionality for managing chart drawings. ```python chart.toolbox.load_drawings('my_tag') ``` -------------------------------- ### Fit Chart Data to Viewport Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Adjust the chart's viewport to fit all currently displayed data. This function is equivalent to calling `fitContent()` and ensures all data points are visible. ```python fit() ``` -------------------------------- ### Configure Chart Legend Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Control the visibility and content of the chart legend. Options include showing/hiding the legend, displaying OHLC, percentage, and line values, and customizing text, color, font size, and font family. ```python legend(_visible : bool_, _ohlc : bool_, _percent : bool_, _lines : bool_, _color : COLOR_, _font_size : int_, _font_family : str_, _text : str_, _color_based_on_candle : bool_) ``` -------------------------------- ### Import Drawings from File (Python) Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/toolbox Imports drawings from a JSON file located at the specified file path. This method is part of the ToolBox class for managing chart visualizations. ```python chart.toolbox.import_drawings('/path/to/drawings.json') ``` -------------------------------- ### Style Candlestick Appearance Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Customize the visual styling of individual candle parts, including up and down colors, wick visibility, border visibility, and the colors for borders and wicks. ```python candle_style(_up_color : COLOR_, _down_color : COLOR_, _wick_enabled : bool_, _border_enabled : bool_, _border_up_color : COLOR_, _border_down_color : COLOR_, _wick_up_color : COLOR_, _wick_down_color : COLOR_) ``` -------------------------------- ### Customize Chart Grid Properties Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Control the visibility and appearance of the chart's grid lines. Options include enabling/disabling vertical and horizontal grids, setting the color, and defining the line style. ```python grid(_vert_enabled : bool_, _horz_enabled : bool_, _color : COLOR_, _style : LINE_STYLE_) ``` -------------------------------- ### StreamlitChart Usage - Python Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/charts The StreamlitChart object is designed for use within Streamlit applications. It supports static data display only and requires calling `load()` after all configurations are complete. Updates via `update_from_tick` or `update` are not supported. ```python import streamlit as st from lightweight_charts.charts import StreamlitChart import pandas as pd # Initialize StreamlitChart # streamlit_chart = StreamlitChart() # Set data, configure, and style the chart # df = pd.read_csv('ohlcv.csv') # streamlit_chart.set(df) # Load the chart into the Streamlit app # streamlit_chart.load() ``` -------------------------------- ### Set Price Precision Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Define the precision of the chart's price scale by specifying the number of decimal places to display. This ensures accurate representation of price values. ```python precision(_precision : int_) ``` -------------------------------- ### Format Crosshair Display Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Customize the appearance of the chart's crosshair, including visibility, width, color, line style, and label background color for both vertical and horizontal axes. ```python crosshair(_mode_ , _vert_visible : bool_, _vert_width : int_, _vert_color : COLOR_, _vert_style : LINE_STYLE_, _vert_label_background_color : COLOR_, _horz_visible : bool_, _horz_width : int_, _horz_color : COLOR_, _horz_style : LINE_STYLE_, _horz_label_background_color : COLOR_) ``` -------------------------------- ### Overlay Watermark on Chart Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Add a watermark to the chart with customizable text, font size, and color. This can be used for branding or informational purposes. ```python watermark(_text : str_, _font_size : int_, _color : COLOR_) ``` -------------------------------- ### ToolBox Class Reference Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/toolbox The ToolBox class allows users to draw and edit trendlines, ray lines, and horizontal lines directly on the chart. It can be enabled by setting the `toolbox` parameter to `True` during chart initialization. The class provides methods for managing saved drawings. ```APIDOC ## ToolBox Class ### Description The Toolbox allows for trendlines, ray lines and horizontal lines to be drawn and edited directly on the chart. It can be used within any Chart object, and is enabled by setting the `toolbox` parameter to `True` upon Chart declaration. ### Hotkeys - `alt T`: Trendline - `alt H`: Horizontal Line - `alt R`: Ray Line - `⌘ Z` or `ctrl Z`: Undo Right-clicking on a drawing will open a context menu for color selection, style selection, and deletion. ### Methods #### `save_drawings_under(widget: Widget)` ##### Description Saves drawings under a specific `topbar` text widget. ##### Parameters - **widget** (Widget) - Required - The topbar text widget to associate the drawings with. ##### Example ```python chart.toolbox.save_drawings_under(chart.topbar['symbol']) ``` #### `load_drawings(tag: str)` ##### Description Loads and displays drawings stored under the given tag. ##### Parameters - **tag** (str) - Required - The tag under which drawings are stored. #### `import_drawings(file_path: str)` ##### Description Imports the drawings stored at the JSON file given in `file_path`. ##### Parameters - **file_path** (str) - Required - The path to the JSON file containing drawings to import. #### `export_drawings(file_path: str)` ##### Description Exports all currently saved drawings to the JSON file given in `file_path`. ##### Parameters - **file_path** (str) - Required - The path to the JSON file where drawings will be exported. ``` -------------------------------- ### Show Hidden Candles Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Make candles that were previously hidden on the chart visible again. This function is used to restore the display of candle data. ```python show_data() ``` -------------------------------- ### Export Drawings to File (Python) Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/toolbox Exports all currently saved drawings to a JSON file at the provided file path. This function is a utility within the ToolBox for persisting chart annotations. ```python chart.toolbox.export_drawings('/path/to/save_drawings.json') ``` -------------------------------- ### Python Row Manipulation Methods Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/tables Explains how to manipulate individual rows within a Lightweight Charts Python table. This includes setting background and text colors for cells, and deleting specific rows. ```python # Assuming 'row' is a Row object obtained from table.new_row() # Set background color for a column row.background_color('Price', 'red') # Set text color for a column row.text_color('Change', 'green') # Delete the row row.delete() ``` -------------------------------- ### Edit Horizontal Line with Callback Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Enable interactive editing of a horizontal line on the chart. When the line is moved, a callback function is triggered with the `HorizontalLine` object. The toolbox must be enabled for this feature. ```python If a `func` is given, the horizontal line can be edited on the chart. Upon its movement a callback will also be emitted to the callable given, containing the HorizontalLine object. The toolbox should be enabled during its usage. It is designed to be used to update an order (limit, stop, etc.) directly on the chart. ``` -------------------------------- ### JupyterChart Usage - Python Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/charts The JupyterChart object allows embedding charts within Jupyter notebooks. Similar to StreamlitChart, it is intended for static data display and requires the `load()` method to be called after all settings are finalized. It does not support dynamic updates. ```python from lightweight_charts.charts import JupyterChart import pandas as pd # Initialize JupyterChart # jupyter_chart = JupyterChart() # Set data, configure, and style the chart # df = pd.read_csv('ohlcv.csv') # jupyter_chart.set(df) # Render the chart in the notebook # jupyter_chart.load() ``` -------------------------------- ### Clear Chart Markers Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Remove all markers that are currently displayed on the chart data. This function provides a way to reset the visual markers on the chart. ```python clear_markers() ``` -------------------------------- ### TopBar Class Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/topbar The TopBar class allows you to add interactive widgets such as switchers, menus, text boxes, and buttons to the top bar of the chart. These widgets can be accessed and manipulated via the chart's topbar attribute. ```APIDOC ## Class TopBar ### Description Represents the top bar shown on the chart. Widgets like switchers, text boxes, and buttons can be added to this bar. ### Access This object is accessed from the `topbar` attribute of the chart object (e.g., `chart.topbar`). ### Common Widget Parameters - `name` (str): The name of the widget, used for access via the `topbar` dictionary. - `align` (ALIGN): The alignment of the widget ('left' or 'right'). * * * ## `TopBar.switcher()` ### Description Adds a switcher widget to the top bar. ### Method `switcher(_name: str_, _options: tuple: default: str_, _align: ALIGN_, _func: callable_) ### Parameters - `name` (str) - Required - The name of the switcher widget. - `options` (tuple) - Required - The available options for the switcher. - `default` (str) - Optional - The initial selected option. - `align` (ALIGN) - Optional - The alignment of the widget ('left' or 'right'). - `func` (callable) - Optional - A function to be called when the switcher's value changes. * * * ## `TopBar.menu()` ### Description Adds a menu widget to the top bar. ### Method `menu(_name: str_, _options: tuple: default: str_, _separator: bool_, _align: ALIGN_, _func: callable_) ### Parameters - `name` (str) - Required - The name of the menu widget. - `options` (tuple) - Required - The available options for the menu. - `default` (str) - Optional - The initial selected option. - `separator` (bool) - Optional - If true, places a separator line to the right of the menu. - `align` (ALIGN) - Optional - The alignment of the widget ('left' or 'right'). - `func` (callable) - Optional - A function to be called when the menu's value changes. * * * ## `TopBar.textbox()` ### Description Adds a textbox widget to the top bar. ### Method `textbox(_name : str_, _initial_text : str_, _align : ALIGN_) ### Parameters - `name` (str) - Required - The name of the textbox widget. - `initial_text` (str) - Required - The initial text to display in the textbox. - `align` (ALIGN) - Optional - The alignment of the widget ('left' or 'right'). * * * ## `TopBar.button()` ### Description Adds a button widget to the top bar. ### Method `button(_name : str_, _button_text : str_, _separator : bool_, _align : ALIGN_, _func : callable_) ### Parameters - `name` (str) - Required - The name of the button widget. - `button_text` (str) - Required - The text to display on the button. - `separator` (bool) - Optional - If true, places a separator line to the right of the button. - `align` (ALIGN) - Optional - The alignment of the widget ('left' or 'right'). - `func` (callable) - Required - The event handler to execute when the button is clicked. ### Example Usage ```python # Assuming 'chart' is an instance of a chart object chart.topbar.textbox('symbol', 'AAPL') print(chart.topbar['symbol'].value) chart.topbar['symbol'].set('MSFT') chart.topbar.button('update_btn', 'Update', func=lambda: print('Button clicked')) ``` ``` -------------------------------- ### Hide Candles on Chart Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart Remove candles from the chart's display. This function can be used to temporarily hide candle data for better visibility of other elements. ```python hide_data() ``` -------------------------------- ### HorizontalLine Class in Python Source: https://lightweight-charts-python.readthedocs.io/en/latest/reference/horizontal_line The HorizontalLine class represents a price line on Lightweight Charts. It is accessed via the `horizontal_line` method. This class allows for updating the price, modifying the label, and deleting the line. ```python class HorizontalLine(_price : NUM_, _color : COLOR_, _width : int_, _style : LINE_STYLE_, _text : str_, _axis_label_visible : bool_, _func : callable = None_): """ The `HorizontalLine` object represents a `PriceLine` in Lightweight Charts. Its instance should be accessed from the `horizontal_line` method. """ def update(_price : NUM_): """ Updates the price of the horizontal line. """ pass def label(_text : str_): """ Updates the label of the horizontal line. """ pass def delete(): """ Irreversibly deletes the horizontal line. """ pass ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.