# Sample Size

> Show how many observations stand behind each point or bar, and mark values that rest on too few.

Source: https://www.honestui.com/docs/charts/honesty/sample-size

### sampleSizeKey=&#x22;responses&#x22;

```tsx
"use client";

import { LineChart, type ChartConfig } from "honestui/charts";

// Scenario: Average satisfaction score out of 5 from a weekly survey (sample
// data). Holiday weeks drew few responses, so their averages are shakier.
const data = [
  { week: "Oct 6", score: 4.1, responses: 212 },
  { week: "Oct 13", score: 4.2, responses: 198 },
  { week: "Oct 20", score: 4.0, responses: 224 },
  { week: "Oct 27", score: 4.6, responses: 18 },
  { week: "Nov 3", score: 4.1, responses: 187 },
  { week: "Nov 10", score: 4.2, responses: 205 },
  { week: "Nov 17", score: 3.5, responses: 22 },
  { week: "Nov 24", score: 4.1, responses: 176 },
];

const chartConfig = {
  score: {
    label: "Satisfaction",
    colors: { light: ["#be185d"], dark: ["#f472b6"] },
  },
} satisfies ChartConfig;

export function ExampleLineChart() {
  return (
    <LineChart data={data} config={chartConfig} className="h-full w-full p-4" xDataKey="week">
      <LineChart.Grid />
      <LineChart.XAxis dataKey="week" />
      <LineChart.YAxis />
      <LineChart.Tooltip />
      <LineChart.Line dataKey="score" sampleSizeKey="responses" minSampleSize={30}>
        <LineChart.Dot variant="border" />
      </LineChart.Line>
    </LineChart>
  );
}

```

## Overview [#overview]

An average from eight survey responses and an average from eight hundred look the same on a chart. The first can swing by twenty points from one week to the next for no reason at all. Readers who cannot see the difference chase noise.

`sampleSizeKey` puts the count beside each value as "n=42". Add `minSampleSize`, and values below it get a dashed ring and a "Fewer than 30" entry in the key, so a thin week reads as thin.

## Usage [#usage]

Put the count in the same row as the value, then name the field on the series:

```tsx
import { LineChart } from "honestui/charts";

const data = [
  { week: "W1", score: 72, responses: 184 },
  { week: "W2", score: 81, responses: 12 },
  // ...
];

<LineChart data={data} config={chartConfig} xDataKey="week">
  <LineChart.XAxis dataKey="week" />
  <LineChart.YAxis />
  <LineChart.Tooltip />
  <LineChart.Line dataKey="score" sampleSizeKey="responses" minSampleSize={30} />
</LineChart>
```

With several series, give each its own count field. A scatter chart has one value per point, so it takes `sampleSizeKey` and `minSampleSize` on the root.

## Behavior to know about [#behavior-to-know-about]

* **Labels or tooltip.** `sampleSizeDisplay="label"` writes "n=…" on the plot, which is the default for line, area, bar, and combo charts. `"tooltip"` keeps the plot clean and shows the count only on hover, which is the default for scatter charts.
* **Thinned labels.** When labels would overlap, the chart shows every second or third one. The tooltip always has the count.
* **Bars.** The label sits above each bar, or past its end in a horizontal layout. A bar below the minimum gets a dashed outline.
* **The threshold is yours.** The chart does not decide what a small sample is. Without `minSampleSize`, counts are shown and nothing is flagged.
* **Missing counts.** A row without a count shows no label and is never flagged.

## Accessibility [#accessibility]

The count is part of each tooltip row, and values below the minimum add a note. The key explains the count and the low-sample mark, and when any value falls below the minimum, the default `ariaLabel` ends with the low-sample label, such as "Fewer than 30."

## Changing the text [#changing-the-text]

| Field                   | Default                                                            |
| ----------------------- | ------------------------------------------------------------------ |
| `sampleSize`            | `(n) => "n=42"`                                                    |
| `sampleSizeLabel`       | "Sample size"                                                      |
| `sampleSizeDescription` | "The number of observations behind each value."                    |
| `lowSampleLabel`        | `(min) => "Fewer than 30"`                                         |
| `lowSampleDescription`  | "Few observations stand behind this value. Treat it with caution." |

See [Honest Charts](/docs/charts/honesty) for the full `honestyText` object.

## Examples [#examples]

### Area chart [#area-chart]

<ComponentPreview title="<AreaChart.Area sampleSizeKey=&#x22;trials&#x22; />" name="ex-sample-size-echarts-area-chart" />

### Bar chart [#bar-chart]

<ComponentPreview title="<BarChart.Bar sampleSizeKey=&#x22;responses&#x22; />" name="ex-sample-size-echarts-bar-chart" />

### Combo chart [#combo-chart]

### sampleSizeKey on a combo chart

```tsx
"use client";

import { ComboChart, type ChartConfig } from "honestui/charts";

// Scenario: Weekly support satisfaction and first response time (sample data).
// Each bar shows how many surveys stand behind it; holiday weeks drew few.
const data = [
  { week: "Oct 27", csat: 91, surveys: 184, response: 2.4 },
  { week: "Nov 3", csat: 89, surveys: 203, response: 2.7 },
  { week: "Nov 10", csat: 92, surveys: 176, response: 2.2 },
  { week: "Nov 17", csat: 90, surveys: 198, response: 2.5 },
  { week: "Nov 24", csat: 97, surveys: 14, response: 1.6 },
  { week: "Dec 1", csat: 88, surveys: 211, response: 3.1 },
  { week: "Dec 8", csat: 91, surveys: 189, response: 2.6 },
  { week: "Dec 15", csat: 79, surveys: 19, response: 3.4 },
];

const chartConfig = {
  csat: {
    label: "Satisfied",
    colors: { light: ["#0d9488"], dark: ["#2dd4bf"] },
  },
  response: {
    label: "First response",
    colors: { light: ["#c2410c"], dark: ["#fb923c"] },
  },
} satisfies ChartConfig;

export function ExampleComboChart() {
  return (
    <ComboChart data={data} config={chartConfig} xDataKey="week" className="h-full w-full p-4">
      <ComboChart.Grid />
      <ComboChart.XAxis />
      <ComboChart.YAxis yAxisId="left" tickFormatter={(value) => `${value}%`} />
      <ComboChart.YAxis yAxisId="right" tickFormatter={(value) => `${value} h`} />
      <ComboChart.Legend />
      <ComboChart.Tooltip
        valueFormatter={(value, key) => (key === "csat" ? `${value}%` : `${value} h`)}
      />
      <ComboChart.Bar dataKey="csat" sampleSizeKey="surveys" minSampleSize={30} />
      <ComboChart.Line dataKey="response" yAxisId="right">
        <ComboChart.Dot variant="border" />
      </ComboChart.Line>
    </ComboChart>
  );
}

```

### Scatter chart [#scatter-chart]

<ComponentPreview title="<ScatterChart sampleSizeKey=&#x22;reviews&#x22; />" name="ex-sample-size-echarts-scatter-chart" />

## API Reference [#api-reference]

<ApiHeading>
  Line, Area, and Bar parts; Combo series; ScatterChart root
</ApiHeading>


  ### `sampleSizeKey`

type: `string`

The row field that holds the number of observations behind the value.

  ### `minSampleSize`

type: `number`

Values with fewer observations than this get a dashed ring or outline and a low-sample entry in the key and tooltip.

  ### `sampleSizeDisplay`

type: `&#x22;label&#x22; | &#x22;tooltip&#x22;` · default: `&#x22;label&#x22;, or &#x22;tooltip&#x22; on ScatterChart`

Where the count appears: on the plot beside each value, or only in the tooltip.
