### Install Highcharts React
Source: https://github.com/highcharts/highcharts-react/blob/master/README.md
Install Highcharts and the React wrapper using npm or yarn. Ensure React and ReactDOM are installed as peer dependencies.
```bash
npm install highcharts @highcharts/react
```
```bash
yarn add highcharts @highcharts/react
```
```bash
npm install react react-dom
```
--------------------------------
### Quick Start: Render a React Chart
Source: https://github.com/highcharts/highcharts-react/blob/master/README.md
Import Chart components and Series types from '@highcharts/react' to create a chart with multiple series. This example demonstrates a basic setup for rendering a chart with line, column, and area series.
```jsx
import React from 'react';
import { createRoot } from 'react-dom/client';
import { Chart, Title, Series } from '@highcharts/react';
import { ColumnSeries } from '@highcharts/react/series/Column';
import { AreaSeries } from '@highcharts/react/series/Area';
export function Application() {
return (
Chart with multiple series types
);
}
const root = createRoot(document.getElementById('root'));
root.render();
```
--------------------------------
### Install Highcharts React and Peer Dependency
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Install the package and its highcharts peer dependency using npm or yarn.
```bash
npm install highcharts @highcharts/react
# or
yarn add highcharts @highcharts/react
```
--------------------------------
### Create a Highcharts Gantt Chart with React Components
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Use the `` component for project timeline visualizations. Import from `@highcharts/react/Gantt`. Define tasks with start and end dates, and configure axes and series declaratively.
```jsx
import React from 'react';
import { GanttChart, Title, XAxis, YAxis } from '@highcharts/react/Gantt';
import { GanttSeries } from '@highcharts/react/series/Gantt';
const tasks = [
{ name: 'Design', start: Date.UTC(2024, 2, 1), end: Date.UTC(2024, 2, 15), completed: { amount: 1 } },
{ name: 'Development', start: Date.UTC(2024, 2, 10), end: Date.UTC(2024, 3, 20), completed: { amount: 0.6 } },
{ name: 'Testing', start: Date.UTC(2024, 3, 15), end: Date.UTC(2024, 4, 5), completed: { amount: 0.1 } },
];
export function ProjectTimeline() {
return (
Project Timeline Q1–Q2 2024
);
}
```
--------------------------------
### Enable Chart Exporting with ``
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Use the `` component to add a menu for downloading charts in various formats (PNG, PDF, CSV, etc.) and for printing. Configure menu items and CSV export options.
```jsx
import React from 'react';
import { Chart, Title } from '@highcharts/react';
import { Exporting } from '@highcharts/react/options/Exporting';
import { ColumnSeries } from '@highcharts/react/series/Column';
export function ExportableChart() {
return (
Exportable Sales Report
);
}
```
--------------------------------
### Create a Highstock Chart with React Components
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Use the `` component for time-series data with navigator and range selector. Import from `@highcharts/react/Stock`. Configure axes, tooltips, and series declaratively.
```jsx
import React from 'react';
import { StockChart, Title } from '@highcharts/react/Stock';
import { CandlestickSeries } from '@highcharts/react/series/Candlestick';
import { XAxis, YAxis, Tooltip } from '@highcharts/react/Stock';
const ohlcData = [
[Date.UTC(2024, 0, 2), 148.5, 151.2, 147.8, 150.3],
[Date.UTC(2024, 0, 3), 150.3, 153.0, 149.5, 152.1],
[Date.UTC(2024, 0, 4), 152.1, 154.8, 151.0, 153.7],
[Date.UTC(2024, 0, 5), 153.7, 155.2, 150.9, 151.5],
];
export function StockPriceChart() {
return (
ACME Corp — Daily OHLC
);
}
```
--------------------------------
### Create a Standard Highcharts Chart with React Components
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Use the `` component as the root for standard Highcharts charts. Nest other option and series components as children. The `ref` prop provides access to the raw Highcharts chart instance.
```jsx
import React, { useRef, useEffect } from 'react';
import { Chart, Title, Series } from '@highcharts/react';
import { ColumnSeries } from '@highcharts/react/series/Column';
import { AreaSeries } from '@highcharts/react/series/Area';
export function SalesChart() {
const chartRef = useRef(null);
useEffect(() => {
if (chartRef.current?.chart) {
// Access the raw Highcharts chart instance
console.log('Chart type:', chartRef.current.chart.options.chart.type);
}
}, []);
return (
Monthly Sales
);
}
```
--------------------------------
### Create a World Population Map with MapsChart
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Use the MapsChart component for geographic map charts. Ensure map data and series data are correctly formatted.
```jsx
import React from 'react';
import { MapsChart, Title, Tooltip } from '@highcharts/react/Maps';
import { MapSeries } from '@highcharts/react/series/Map';
import mapData from '@highcharts/map-collection/custom/world.geo.json';
const populationData = [
{ 'hc-key': 'us', value: 331000000 },
{ 'hc-key': 'cn', value: 1411000000 },
{ 'hc-key': 'br', value: 214000000 },
];
export function WorldPopulationMap() {
return (
World Population
);
}
```
--------------------------------
### Customize Tooltip with HTML and Shared Data
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Implement a custom tooltip using the Tooltip component. Supports shared data, HTML content formatting, and various styling options like background color, border, and shadow. The formatter function allows dynamic generation of tooltip content based on chart data.
```jsx
import React from 'react';
import { Chart, Title, Tooltip } from '@highcharts/react';
import { ColumnSeries } from '@highcharts/react/series/Column';
import { XAxis } from '@highcharts/react';
export function CustomTooltipChart() {
return (
Sales by Quarter
`● ${p.series.name}: $${p.y}K`)
.join('
');
return `${this.x}
${points}`;
}}
backgroundColor="rgba(255,255,255,0.95)"
borderColor="#ccc"
borderRadius={8}
shadow={true}
/>
);
}
```
--------------------------------
### Create a Chart with Mixed Typed Series Components
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Utilize dedicated typed series components (e.g., ColumnSeries, LineSeries, BubbleSeries) for enhanced TypeScript autocompletion. These are intended for use within an existing Chart component.
```jsx
import React from 'react';
import { Chart, Title, XAxis, YAxis } from '@highcharts/react';
import { ColumnSeries } from '@highcharts/react/series/Column';
import { LineSeries } from '@highcharts/react/series/Line';
import { BubbleSeries } from '@highcharts/react/series/Bubble';
const categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May'];
export function MixedTypedSeriesChart() {
return (
Typed Series Components
);
}
```
--------------------------------
### Register Custom Highcharts Instance with `setHighcharts`
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Use `setHighcharts` to register a custom Highcharts instance, potentially with modules applied, and `getHighcharts` to retrieve it. This is useful for pre-configured or modified Highcharts environments.
```jsx
import React from 'react';
import Highcharts from 'highcharts/esm/highcharts.src.js';
import HighchartsMore from 'highcharts/esm/highcharts-more.src.js';
import Accessibility from 'highcharts/esm/modules/accessibility.src.js';
import { setHighcharts, getHighcharts, Chart, Title } from '@highcharts/react';
import { GaugeSeries } from '@highcharts/react/series/Gauge';
// Apply modules to custom instance
HighchartsMore(Highcharts);
Accessibility(Highcharts);
// Register with @highcharts/react
setHighcharts(Highcharts);
// Verify the instance is registered
const hc = getHighcharts();
console.log('Using Highcharts with modules:', hc.__provided); // true
export function GaugeChart() {
return (
Speedometer
);
}
```
--------------------------------
### Create a Multi-Series Chart with Generic Series Component
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Use the generic Series component to add multiple series of different types to a chart. The series type is inferred at runtime.
```jsx
import React from 'react';
import { Chart, Title, Series } from '@highcharts/react';
export function MultiSeriesChart() {
return (
Chart with multiple series types
{/* Generic Series — type inferred at runtime */}
);
}
```
--------------------------------
### Implement Drilldown Functionality with Series Data
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Enable drilldown on chart data points using the Drilldown component. This requires defining drilldown series and linking them to data points via the 'drilldown' property. Customize active label styles for drilldown interactions.
```jsx
import React from 'react';
import { Chart, Title, Drilldown, XAxis, YAxis } from '@highcharts/react';
import { ColumnSeries } from '@highcharts/react/series/Column';
const drilldownSeries = [
{ id: 'q1', name: 'Q1 Breakdown', type: 'column', data: [{ name: 'Jan', y: 38 }, { name: 'Feb', y: 41 }, { name: 'Mar', y: 41 }] },
{ id: 'q2', name: 'Q2 Breakdown', type: 'column', data: [{ name: 'Apr', y: 45 }, { name: 'May', y: 52 }, { name: 'Jun', y: 48 }] },
];
export function DrilldownChart() {
return (
Annual Sales — Click to drill down
);
}
```
--------------------------------
### Style Chart Legend with Layout and Item Styles
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Control the chart legend's appearance and behavior using the Legend component. Options include layout (horizontal/vertical), alignment, item styling (font weight, size), hover styles, and border/padding configurations. This allows for a customized legend that fits the chart's design.
```jsx
import React from 'react';
import { Chart, Title, Legend } from '@highcharts/react';
import { LineSeries } from '@highcharts/react/series/Line';
export function StyledLegendChart() {
return (
Market Indices
);
}
```
--------------------------------
### Integrate Technical Indicators with StockChart
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Add technical analysis indicators like SMA, BB, and MACD to a StockChart. Indicators require a linked series `id` and are configured via their respective components.
```jsx
import React from 'react';
import { StockChart, Title, XAxis, YAxis } from '@highcharts/react/Stock';
import { CandlestickSeries } from '@highcharts/react/series/Candlestick';
import { SMASeries } from '@highcharts/react/indicators/SMA';
import { BBSeries } from '@highcharts/react/indicators/BB';
import { MACDSeries } from '@highcharts/react/indicators/MACD';
const priceData = [
[Date.UTC(2024, 0, 2), 148.5, 151.2, 147.8, 150.3],
[Date.UTC(2024, 0, 3), 150.3, 153.0, 149.5, 152.1],
[Date.UTC(2024, 0, 4), 152.1, 154.8, 151.0, 153.7],
[Date.UTC(2024, 0, 5), 153.7, 155.2, 150.9, 151.5],
[Date.UTC(2024, 0, 8), 151.5, 156.0, 150.0, 155.2],
[Date.UTC(2024, 0, 9), 155.2, 157.8, 154.1, 157.0],
];
export function TechnicalAnalysisChart() {
return (
ACME — Technical Analysis
{/* Main price pane */}
{/* MACD pane */}
);
}
```
--------------------------------
### Enable Debug Logging with Logger
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Control internal logging verbosity using the Logger object. Set logLevel to 'debug' during development to trace chart updates. Suppress all logging in production by setting it to 'silent'.
```jsx
import { Logger, Chart, Series } from '@highcharts/react';
// Enable debug logging in development
if (process.env.NODE_ENV === 'development') {
Logger.logLevel = 'debug';
}
// Suppress all logging in production (default)
Logger.logLevel = 'silent';
// Manually emit a log entry
Logger.log('Chart initialized', { timestamp: Date.now() });
export function DebugChart() {
return (
);
}
```
--------------------------------
### Add Title and Subtitle to a Chart
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Use the Title and Subtitle components to add text elements to your chart. Text can be provided as children or via the 'text' prop, and styling/alignment options are available.
```jsx
import React from 'react';
import { Chart, Title, Series } from '@highcharts/react';
import { Subtitle } from '@highcharts/react/options/Subtitle';
export function TitledChart() {
return (
Annual Revenue Report
Fiscal Year 2024
);
}
```
--------------------------------
### Configure XAxis and YAxis with Plot Bands and Lines
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Use XAxis and YAxis components to define chart axes. Supports datetime types, categories, plot bands, plot lines, label formatting, and crosshairs. Configure axis titles, min/max values, and visual elements like plot bands and lines.
```jsx
import React from 'react';
import { Chart, Title } from '@highcharts/react';
import { XAxis, YAxis } from '@highcharts/react';
import { LineSeries } from '@highcharts/react/series/Line';
export function AnnotatedAxesChart() {
return (
Temperature Over Time
);
}
```
--------------------------------
### Customize Chart Container with containerProps
Source: https://context7.com/highcharts/highcharts-react/llms.txt
Pass any HTML div attributes directly to the chart's wrapping container for layout control, CSS classes, or data attributes. This allows for flexible styling and accessibility.
```jsx
import React from 'react';
import { Chart, Title, Series } from '@highcharts/react';
export function ResponsiveChart() {
return (
Responsive Sales Chart
);
}
```
--------------------------------
### Customize Chart Container Props
Source: https://github.com/highcharts/highcharts-react/blob/master/README.md
Pass props directly to the chart's container div using `containerProps`. This allows for setting styles, classes, or data attributes on the container element.
```jsx
Full-width chart
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.