JavaScript Mountain Chart Draggable Thresholds

Demonstrates interaction by dragging vertical and horizontal line thresholds on a mountain chart. As the thresholds move, the chart colour updates. The vertical mountain fill is done using a separate renderableSeries and a dataFilter which reshapes the data to draw only the portion above the threshold.

Fullscreen

Edit

 Edit

Docs

drawExample.ts

Copy to clipboard
Minimise
Fullscreen
1// Loading ... 

Drag Horizontal Threshold - JavaScript

Overview

This example demonstrates an interactive mountain chart built using JavaScript and SciChart.js. It highlights dynamic interaction by using draggable annotations that adjust both visual thresholds and underlying data filters.

Technical Implementation

The chart is initialized asynchronously via SciChartSurface.create(), which sets up the WebAssembly context for high-performance rendering. A custom data filter, implemented as the ThresholdFilter class by extending XyFilterBase, processes the data to display only regions above a specified threshold. Additionally, the custom palette provider (XThresholdPaletteProvider) overrides fill colors based on x-values relative to a defined threshold. These components work together to update chart visuals in real time as users interact with the graphic elements. For more details, refer to the Creating a Custom Filter and The PaletteProvider API documentation.

Features and Capabilities

This example includes several advanced features:

  • Interactive Draggable Annotations: Both horizontal and vertical lines are made draggable using onDrag event handlers, enabling dynamic modification of threshold values. See Editable Annotations for additional insights.
  • Dynamic Chart Updates: As the user moves the threshold lines, the chart updates immediately using SciChartSurface.invalidateElement(), ensuring real-time feedback.
  • High-Performance Rendering: Utilizing FastMountainRenderableSeries along with WebGL capabilities and optimized data handling ensures smooth performance even with high data volumes. Developers can explore related techniques in the Performance Tips & Tricks guide.

Integration and Best Practices

This implementation follows best practices for integrating SciChart.js in a JavaScript environment. The separation of data filtering and visual elements into bespoke components (i.e., ThresholdFilter and XThresholdPaletteProvider) allows for modular, maintainable code. Developers are encouraged to refer to Creating a new SciChartSurface and loading Wasm for more context on initializing the chart with WebAssembly and to leverage interactive modifiers such as ZoomPanModifier, ZoomExtentsModifier, and MouseWheelZoomModifier for an enhanced user experience.

SciChart Ltd, 16 Beaufort Court, Admirals Way, Docklands, London, E14 9XL.