For an example that demonstrates how create a React Pie Chart, our demo code teaches you how to do this with SciChart's JavaScript Charting Library.
drawExample.ts
index.tsx
theme.ts
1import { appTheme } from "../../../theme";
2import {
3 EPieType,
4 ELegendOrientation,
5 ELegendPlacement,
6 GradientParams,
7 Point,
8 PieSegment,
9 SciChartPieSurface,
10} from "scichart";
11
12export const drawExample = async (rootElement: string | HTMLDivElement) => {
13 // Create the pie chart
14 const sciChartPieSurface = await SciChartPieSurface.create(rootElement, {
15 theme: appTheme.SciChartJsTheme,
16 pieType: EPieType.Pie,
17 animate: true,
18 seriesSpacing: 15,
19 showLegend: true,
20 showLegendSeriesMarkers: true,
21 animateLegend: true,
22 });
23 // Optional placement of legend
24 sciChartPieSurface.legend.orientation = ELegendOrientation.Horizontal;
25 sciChartPieSurface.legend.placement = ELegendPlacement.BottomLeft;
26
27 // SciChart.js expects a list of PieSegment, however data is often formatted like this
28 // Dataset = 'percentage market share of phones, 2022'
29 const dataset = [
30 { name: "Apple", percent: 28.41 },
31 { name: "Samsung", percent: 28.21 },
32 { name: "Xiaomi", percent: 12.73 },
33 { name: "Huawei", percent: 5.27 },
34 { name: "Oppo", percent: 5.53 },
35 { name: "Vivo", percent: 4.31 },
36 { name: "Realme", percent: 3.16 },
37 { name: "Motorola", percent: 2.33 },
38 { name: "Unknown", percent: 2.19 },
39 { name: "LG", percent: 0.85 },
40 { name: "OnePlus", percent: 1.11 },
41 { name: "Tecno", percent: 1.09 },
42 { name: "Infinix", percent: 0.96 },
43 { name: "Google", percent: 0.77 },
44 { name: "Nokia", percent: 0.45 },
45 ];
46
47 // Colors are just hex strings, supporting #FFFFFF (RBG) or 8-digit with RGBA or CSS color strings e.g. rgba()
48 const colors = [
49 { color1: appTheme.VividOrange, color2: appTheme.MutedOrange },
50 { color1: appTheme.Indigo, color2: appTheme.VividBlue },
51 { color1: appTheme.MutedSkyBlue, color2: appTheme.MutedTeal },
52 { color1: appTheme.MutedTeal, color2: appTheme.PaleTeal },
53 { color1: appTheme.VividSkyBlue, color2: appTheme.MutedSkyBlue },
54 { color1: appTheme.MutedRed },
55 { color1: appTheme.MutedPink },
56 { color1: appTheme.VividPink },
57 { color1: appTheme.VividPurple },
58 { color1: appTheme.MutedOrange },
59 { color1: appTheme.VividOrange },
60 { color1: appTheme.PaleTeal },
61 { color1: appTheme.PaleBlue },
62 { color1: appTheme.PaleOrange },
63 { color1: appTheme.PalePink },
64 ];
65
66 // Optional Relative radius adjustment per segment
67 const radiusSize = [0.8, 0.8, 0.8, 0.8, 0.85, 0.85, 0.85, 0.9, 0.9, 0.9, 0.95, 0.95, 0.95, 0.95, 0.95];
68
69 const toPieSegment = (name: string, value: number, radiusAdjustment: number, color1: string, color2: string) => {
70 return new PieSegment({
71 value,
72 text: name,
73 labelStyle: { color: appTheme.ForegroundColor },
74 radiusAdjustment,
75 showLabel: value > 2,
76 colorLinearGradient: new GradientParams(new Point(0, 0), new Point(0, 1), [
77 { color: color1, offset: 0 },
78 { color: color2 || color1 + "77", offset: 1 },
79 ]),
80 });
81 };
82
83 // Transform the data to pie segment and add to scichart
84 const pieSegments = dataset.map((row, index) =>
85 toPieSegment(row.name, row.percent, radiusSize[index], colors[index].color1, colors[index].color2)
86 );
87
88 sciChartPieSurface.pieSegments.add(...pieSegments);
89
90 return { sciChartSurface: sciChartPieSurface };
91};
92This example demonstrates how to create a high performance React Pie Chart using SciChart.js in a React application. The example visualizes market share data of mobile phone manufacturers for 2022 and focuses on delivering an animated, responsive pie chart with advanced styling options such as gradient fills and dynamically adjusted segment radii.
The chart is initialized asynchronously using a callback pattern within the React component. In the main component, the <SciChartReact/> component from the SciChart-React package is utilized to encapsulate the chart configuration and rendering. The asynchronous initialization approach, detailed in Creating a SciChart React Component from the Ground Up, ensures that the chart is properly rendered once the underlying webgl context is ready. The example leverages the SciChartPieSurface to configure properties such as animation, legend layout, series spacing, and gradient colors for each PieSegment.
The example showcases several advanced features including animated transitions, customizable gradient fills using linear gradients, and relative radius adjustments per segment. Each pie segment is constructed programmatically from a dataset to highlight the flexibility in handling real-world data. The chart also includes interactive elements like legends with configurable orientation and placement, enhancing the overall user experience. Additionally, performance optimizations are inherent through efficient canvas rendering, a subject discussed in detail in React Charts with SciChart.js: Introducing “SciChart React”.
This example exemplifies best practices for integrating SciChart.js with React. It uses the <SciChartReact/> component for seamless integration of asynchronous chart initialization and relies on callback functions to manage the chart lifecycle. Resource cleanup is handled elegantly to ensure optimal performance and stability over time. Developers looking to further optimize their projects can refer to Tutorial 01 - Setting up a project with scichart-react and config object for more guidance on managing component lifecycle and React Chart Data Animation | SciChart.js Demo for insights on implementing smooth animations.

Discover how to create a high performance React Line Chart with SciChart - the leading JavaScript library. Get your free demo now.

Discover how to create a React Spline Line Chart with SciChart. Demo includes algorithm for smoother lines. Get your free trial now.

Discover how to create a React Digital Line Chart with SciChart - your feature-rich JavaScript Chart Library. Get your free demo now.

Easily create a React Band Chart or High-Low Fill with SciChart - high performance JavaScript Chart Library. Get your free trial now.

SciChart's React Spline Band Chart makes it easy to draw thresholds or fills between two lines on a chart. Get your free demo today.

Learn how to create a React Digital Band Chart or High-Low Fill Chart with SciChart's easy-to-follow demos. Get your free trial today.

Create a high performance React Bubble Chart with Sci-Chart. Demo shows how to draw point-markers at X,Y locations. Get your free demo now.

Discover how to create a React Candlestick Chart or Stock Chart using SciChart.js. For high Performance JavaScript Charts, get your free demo now.

React Column Chart demo by SciChart supports gradient fill and paletteproviders for more custom coloring options. Get your free demo now.

Population Pyramid of Europe and Africa

Create React Error Bars Chart using high performance SciChart.js. Display uncertainty or statistical confidence of a data-point. Get free demo now.

Easily create React Impulse Chart or Stem Chart using SciChart.js - our own high performance JavaScript Chart Library. Get your free trial now.

Create React Text Chart with high performance SciChart.js.

Discover how to create React Fan Chart with SciChart. Zoom in to see the detail you can go to using our JavaScript Charts. Get your free demo today.

Easily create a high performance React Heatmap Chart with SciChart. Get your free trial of our 5-star rated JavaScript Chart Component today.

Create React Non Uniform Chart using high performance SciChart.js. Display Heatmap with variable cell sizes. Get free demo now.

Design a highly dynamic React Heatmap Chart With Contours with SciChart's feature-rich JavaScript Chart Library. Get your free demo today.

Design a highly dynamic React Map Chart with Heatmap overlay with SciChart's feature-rich JavaScript Chart Library. Get your free demo today.

Create React Mountain Chart with SciChart.js. Zero line can be zero or a specific value. Fill color can be solid or gradient as well. Get a free demo now.

React Spline Mountain Chart design made easy. Use SciChart.js' JavaScript Charts for high performance, feature-rich designs. Get free demo now.

Create React Digital Mountain Chart with a stepped-line visual effect. Get your free trial of SciChart's 5-star rated JavaScript Chart Component now.

React Realtime Mountain Chart made easy. Add animated, real-time updates with SciChart.js - high performance JavaScript Charts. Get free trial now.

Create React Scatter Chart with high performance SciChart.js. Easily render pre-defined point types. Supports custom shapes. Get your free trial now.

Discover how to create a React Stacked Column Chart using our feature-rich JavaScript Chart Library, SciChart.js. Get your free demo today!

Design React Stacked Group Column Chart side-by-side using our 5-star rated JavaScript Chart Framework, SciChart.js. Get your free demo now.

Design a high performance React Stacked Mountain Chart with SciChart.js - your one-stop JavaScript chart library. Get free demo now to get started.

Design a high performance React Stacked Mountain Chart with SciChart.js - your one-stop JavaScript chart library. Get free demo now to get started.

Create React Donut Chart with 5-star rated SciChart.js chart library. Supports legends, text labels, animated updates and more. Get free trial now.

View the React Linear Gauge Chart example to combine rectangles & annotations. Create a linear gauge dashboard with animated indicators and custom scales.

Demonstrates how to color areas of the chart surface using background Annotations using SciChart.js Annotations API

Create a React Histogram Chart with custom texture fills and patterns. Try the SciChartReact wrapper component for seamless React integration today.

Build a React Gantt Chart with SciChart. View the demo for horizontal bars, rounded corners and data labels to show project timelines and task completion.

Create a React Choropleth map, a type of thematic map where areas are shaded or patterned in proportion to the value of a variable being represented.

Create a React Multi-Layer Map Example, using FastTriangleRenderableSeries with GeoJSON data-points using a constrained delaunay triangulation algorithm.

View the React Vector Field Plot example from SciChart, including dynamic vector generation, gradient-colored segments, and interactive zoom/pan. Try demo.

Build a React Waterfall Chart with dynamic coloring, multi-line data labels and responsive design, using the SciChartReact component for seamless integration.

Try the React Box Plot Chart example for React-friendly chart lifecycle management, dynamic sub-surface positioning, and custom styling. Try the demo now.

Create React Triangle Meshes with the Triangle Series from SciChart. This demo supports strip mode, list mode and the drawing of polygons. View the example.

Create a React Treemap Chart to define rectangle positions based on total value. Use SciChart FastRectangleRenderableSeries and d3-hierarchy.js layouts.