TradingView.Blazor 2022.11.26.144

.NET 6.0
dotnet add package TradingView.Blazor --version 2022.11.26.144
NuGet\Install-Package TradingView.Blazor -Version 2022.11.26.144
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TradingView.Blazor" Version="2022.11.26.144" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TradingView.Blazor --version 2022.11.26.144
#r "nuget: TradingView.Blazor, 2022.11.26.144"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TradingView.Blazor as a Cake Addin
#addin nuget:?package=TradingView.Blazor&version=2022.11.26.144

// Install TradingView.Blazor as a Cake Tool
#tool nuget:?package=TradingView.Blazor&version=2022.11.26.144

TradingView.Blazor

Nuget

Simple component for basic TradingView chart in Blazor supporting OHLC candle, volume and markers.

Preview

View the demo

image

Getting Started

1. Include TradingView's lightweight-charts library in the <head>section of your _Host.cs for Blazor Server or wwwroot/index.html for WebAssembly file:

<script src="https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js"></script>

2a. Add the chart to your page where you would like the chart to display with a reference:

<TradingViewChart @ref=myChart />

2b. Define the reference in the @code section of your razor page

@code {
	TradingViewChart? myChart;
}

3. Prepare your data in the format of List<TradingView.Blazor.Models.Ohlcv>

public class Ohlcv
{
    public DateTime Time { get; set; }
    public decimal Open {  get; set; }
    public decimal High { get; set; }
    public decimal Low { get; set; }
    public decimal Close { get; set; }
    public decimal Volume { get; set; }
}

4. Load the chart after render

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    // Only on first render
    if (!firstRender)
        return;

    // Load the data
    ChartData data = new()
    {
        ChartEntries = new List<IChartEntry>(chartService.GetSampleData()),
        MarkerData = new List<Marker>(), // See demo for example
    };

    // Optionally define options
    ChartOptions options = new()
    {
        TimeScaleSecondsVisible = false,

        // Setting width to a negative value makes the chart responsive
        Width = -75,
    };

    // Load the chart
    if (myChart != null)
        await myChart.LoadChartAsync(data, options);
}

5. Update the chart with new or added data by calling LoadChartAsync()

public async Task UpdateChart(ChartData updatedChartData) 
{
    await myChart.UpdateChartAsync(updatedChartData);
}

Demo

You can view the code to the demo's index page here.

Advanced

Custom Definitions

When creating a chart, you can pass in custom definitions that to be interpreted by the native TradingView Lightweight library like so:

var options = new ChartOptions();

// CustomChartDefinitions are interpreted by the library's createChart()
options.CustomChartDefinitions["height"] = 500;

// CustomCandleSeriesDefinitions are interpreted by the library's addCandlestickSeries()
options.CustomCandleSeriesDefinitions["borderVisible"] = false;

// CustomVolumeSeriesDefinitions are interpreted by the library's addHistogramSeries()
options.CustomVolumeSeriesDefinitions["color"] = "#26a69a";
Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2022.11.26.144 308 11/26/2022
2022.11.26.125 174 11/26/2022
2022.11.24.2153 178 11/24/2022
2022.11.24.2130 179 11/24/2022
1.0.5 348 7/18/2022
1.0.4 1,230 11/7/2021
1.0.3 221 11/7/2021
1.0.2 274 10/10/2021
1.0.0 232 8/23/2021