This example demonstrates FastTextRenderableSeries using SciChart.js. The dataset is an AI analysis of 2100 tweets, extracting the organisations mentioned and the sentiment of the tweet.
import { appTheme } from "./appTheme";
import { baseUrl } from "./ExampleDataProvider";
import {
SciChartSurface,
NumericAxis,
NumberRange,
ZoomPanModifier,
ZoomExtentsModifier,
MouseWheelZoomModifier,
LogarithmicAxis,
ENumericFormat,
XyTextDataSeries,
FastTextRenderableSeries,
} from "scichart";
// tslint:disable:no-empty
export const drawExample = async (rootElement: string | HTMLDivElement) => {
// Create a SciChartSurface
const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
theme: appTheme.SciChartJsTheme,
});
const xAxis = new LogarithmicAxis(wasmContext, {
axisTitle: "Number of Tweets",
logBase: 2,
labelFormat: ENumericFormat.SignificantFigures,
growBy: new NumberRange(0, 0.1),
});
sciChartSurface.xAxes.add(xAxis);
sciChartSurface.yAxes.add(
new NumericAxis(wasmContext, {
axisTitle: "Average Sentiment",
labelPrecision: 2,
visibleRange: new NumberRange(0, 1.01),
visibleRangeLimit: new NumberRange(0, 1.01),
})
);
// data is { xValues: number[], yValues: number[], textValues: string[] }
const data: { xValues: number[]; yValues: number[]; textValues: string[] } = await fetch(
baseUrl + "api/tweetData"
).then((r) => r.json());
const series = new FastTextRenderableSeries(wasmContext, {
dataLabels: { style: { fontFamily: "Arial", fontSize: 10 }, calculateTextBounds: false },
dataSeries: new XyTextDataSeries(wasmContext, data),
});
sciChartSurface.renderableSeries.add(series);
sciChartSurface.chartModifiers.add(
new ZoomPanModifier({ enableZoom: true }),
new ZoomExtentsModifier(),
new MouseWheelZoomModifier()
);
return { sciChartSurface, wasmContext };
};
This example demonstrates how to create a high-performance text chart using SciChart.js in a JavaScript application. The chart visualizes AI-analyzed tweet data, showing the number of tweets on a logarithmic x-axis and the average sentiment on a numeric y-axis, rendered as text.
The chart is initialized asynchronously using the SciChartSurface.create() method which sets up a WebAssembly context for optimal performance. For more details on this asynchronous initialization, refer to the Getting Started with SciChart JS guide and the Creating a new SciChartSurface and loading Wasm documentation. The x-axis is configured as a LogarithmicAxis (see The Logarithmic Axis) while the y-axis is set up with a NumericAxis, ensuring proper display ranges. Data is fetched asynchronously via a REST API call and bound to an XyTextDataSeries, which is then rendered using FastTextRenderableSeries as explained in The Text Series documentation.
This implementation includes advanced interactive features such as zooming and panning. The chart modifiers (ZoomPanModifier, ZoomExtentsModifier, and MouseWheelZoomModifier) enable dynamic user interactions and can be reviewed in further detail in the Tutorial 03 - Adding Zooming, Panning Behavior guide. Additionally, custom theming is applied using an appTheme, contributing to a polished and consistent visual appearance.
The example follows best practices in JavaScript by utilizing asynchronous operations for efficient data fetching and WebAssembly for rendering performance. It also incorporates a resource management approach by providing a cleanup function that disposes of the SciChartSurface instance when it is no longer needed, addressing concerns detailed in the Memory Best Practices documentation. This strategy ensures proper disposal of resources and helps prevent memory leaks, aligning with the recommended practices outlined in the SciChart documentation.








































