Skip to content
+

useDataset

Access the dataset used to populate series and axes data.

The useDataset hook provides access to the dataset array that was passed to the chart. This is useful when you need to access the raw data for custom components or calculations.

To access the computed series and axes data, use the useSeries and useAxes hooks instead.

Usage

import { useDataset } from '@mui/x-charts/hooks';

function CustomComponent() {
  const dataset = useDataset();
  // Access the raw dataset array
}

The hook returns the dataset array that was passed to the dataset prop of the chart, or undefined if no dataset was provided.

Basic example

This example demonstrates using the useDataset hook to display dataset statistics above a chart:

Total Revenue
$19,550
Total Expenses
$30,406
Net Profit
$-10,856
Data Points
7
  • Revenue
  • Expenses

Advanced example

This example shows how to use the dataset to create a custom data table that synchronizes with the chart:

Quarterly Sales Report
  • Q1
  • Q2
  • Q3
  • Q4
ProductQ1Q2Q3Q4Total
Product A$4,000$3,000$2,000$2,780$11,780
Product B$3,000$1,398$9,800$3,908$18,106
Product C$2,000$9,800$3,000$4,800$19,600
Product D$2,780$3,908$4,000$3,800$14,488
Product E$1,890$4,800$2,390$3,800$12,880
Total$13,670$22,906$21,190$19,088$76,854

Return value

The hook returns:

Type Description
Readonly<DatasetType> | undefined The dataset array passed to the chart, or undefined if no dataset was provided.

The DatasetType is an array of objects where each object represents a data point with various properties. For example:

const dataset = [
  { month: 'Jan', sales: 100, expenses: 80 },
  { month: 'Feb', sales: 150, expenses: 90 },
  { month: 'Mar', sales: 120, expenses: 70 },
];

When to use

The useDataset hook is particularly useful when:

  • Creating custom components that need access to the raw data
  • Building data tables or summaries alongside your charts
  • Performing calculations on the full dataset

Caveats

This hook must be used within a chart context. See the hooks overview for more information about proper usage.