Using the Chart Component in Extensions
This document describes how to use WealthLab 9 chart components in your own extensions. The chart components are located in the WealthLab.ChartWPF assembly, so add a reference to this assembly in addition to the other assemblies required by your extension.
Note: For a complete example of using the chart components in an extension, see the open-source Extension Demo Project on GitHub.
The chart components in WealthLab.ChartWPF are organized around two primary classes:
- CoreChart - A lightweight chart containing the charting surface without the toolbar or status bar.
- Chart - A higher-level chart component that contains a CoreChart along with a toolbar and status bar.
Accessing the Host (WL9) Environment
The IHost interface provides access to the current WealthLab environment. Extensions can use it to retrieve application-level information and services, such as the location of the user's WealthLab data folder or the DataSets defined by the user.
You can access the current IHost instance from anywhere in your extension through the WLHost singleton and its Instance property. For example, the following code retrieves the path to the user's WealthLab data folder:
string folder = WLHost.Instance.DataFolder;
Use WLHost.Instance whenever your extension needs access to functionality exposed by the IHost interface.
Working with CoreChart
The first tab of the Extension Demo Project contains four CoreChart instances arranged in a 2x2 grid. Examine the XAML and C# code in that project for an example of adding CoreChart to your extension.
public void Refresh(bool fullRefresh)
Causes the chart to refresh.
This can be useful after changing chart properties or values in ChartPreferences. The chart uses two-pass rendering. The first pass renders the underlying chart data, while the second pass renders transient elements such as chart cursors. Set fullRefresh to:
trueto perform both rendering passes.falseto perform only the transient rendering pass.
public BarHistory Bars
Assign a BarHistory instance to this property to display its data in the chart.
public ChartPreferences ChartPreferences
Contains the cosmetic and display settings used by the chart. Assigning a new ChartPreferences instance causes the chart to refresh using the new settings.
public bool IsCrosshairEnabled
public bool IsVerticalBarEnabled
Control the visibility of the chart's crosshair and vertical bar cursors.
public bool IsStreaming
Controls whether the chart is streaming real-time data. Setting this property to true causes the chart to use the currently selected Streaming Data Provider.
public bool ActivateStreamingWith(StreamingProviderBase sb)
Starts streaming using the specific StreamingProviderBase instance supplied in sb.
Note: CoreChart exposes additional properties, methods, and events beyond those documented here. For questions about a specific capability, use the WealthLab Discussion Forum.
Working with Chart
The second tab of the Extension Demo Project contains a Chart component that allows users to select Indicators and plot them on the chart. Examine the XAML and C# code in that project for an example of adding the Chart component to your extension.
public void ChartThisSymbol(string symbol, DataSet ds = null)
Loads and charts historical data for the specified symbol. Optionally, supply a DataSet in ds to have the chart load the symbol using that DataSet's configured Historical Data Provider and settings.
public CoreChart Core
Returns the CoreChart instance contained within the Chart component. Use this property when you need direct access to lower-level CoreChart functionality.
public void InstallContextMenuItem(
string text,
ImageSource imgsrc,
RoutedEventHandler handler)
Adds a custom item to the chart's right-click context menu. The parameters specify the menu item's text, optional image, and event handler.
public bool AllowStreaming
Controls whether the Streaming button is displayed in the chart toolbar.
public bool IsStreaming
Indicates whether the chart is currently streaming real-time data.
Note: Chart exposes additional properties, methods, and events beyond those documented here. For questions about a specific capability, use the WealthLab Discussion Forum.