Skip to main content
Point
@coinbase/cds-web-visualization@3.4.0-beta.1
Import
import { Point } from '@coinbase/cds-web-visualization'
SourceView source code
Related components

Basic Example

Points are visual markers that highlight specific data values on a chart. They can be used to emphasize important data points, show discrete values, or provide interactive elements.

Loading...
Live Code
<LineChart
  enableScrubbing
  height={250}
  series={[
    {
      id: 'prices',
      data: [10, 22, 29, 45, 98, 45, 22, 52, 21, 4, 68, 20, 21, 58],
    },
  ]}
  curve="monotone"
  showYAxis
  showArea
  yAxis={{
    showGrid: true,
  }}
  renderPoints={() => true}
>
  <Scrubber />
</LineChart>

Conditional Points

You can conditionally render points to highlight specific values in your data, such as maximum/minimum values or outliers.

Loading...
Live Code
function AssetPriceWithMinMax() {
  const data = sparklineInteractiveData.hour.map((d) => d.value);

  const minPrice = Math.min(...data);
  const maxPrice = Math.max(...data);

  const formatPrice = useCallback((price: number) => {
    return new Intl.NumberFormat('en-US', {
      style: 'currency',
      currency: 'USD',
    }).format(price);
  }, []);

  return (
    <LineChart
      series={[
        {
          id: 'btc',
          data: data,
          color: assets.btc.color,
        },
      ]}
      showArea
      areaType="dotted"
      height={300}
      style={{ outlineColor: assets.btc.color }}
      renderPoints={({ dataX, dataY }) => {
        const isMin = dataY === minPrice;
        const isMax = dataY === maxPrice;

        if (isMin) {
          return { label: formatPrice(dataY), labelProps: {  dy: 6, verticalAlignment: 'top' } };
        }

        if (isMax) {
          return { label: formatPrice(dataY), labelProps: { dy: -6, verticalAlignment: 'bottom' } };
        }
      }}
    />
  );
};

Interactive Points

Points can be made interactive by adding click handlers, allowing users to explore data in more detail.

Loading...
Live Code
<LineChart
  height={250}
  series={[
    {
      id: 'sales',
      data: [120, 132, 101, 134, 90, 230, 210, 120, 180, 190, 210, 176],
    },
  ]}
  curve="monotone"
  showYAxis
  showArea
  yAxis={{
    showGrid: true,
    label: 'Sales (units)',
  }}
  renderPoints={({ dataX, dataY }) => {
    const months = [
      'Jan',
      'Feb',
      'Mar',
      'Apr',
      'May',
      'Jun',
      'Jul',
      'Aug',
      'Sep',
      'Oct',
      'Nov',
      'Dec',
    ];
    return {
      radius: 4,
      onClick: () => alert(`${months[dataX]}: ${dataY} units sold`),
      accessibilityLabel: `${months[dataX]} sales: ${dataY} units`,
    };
  }}
/>

Customization

Points support extensive customization through various properties including colors, sizes, animations, and labels.

Loading...
Live Code
<LineChart
  height={300}
  series={[
    {
      id: 'performance',
      data: [65, 70, 72, 85, 88, 92, 78, 82, 90, 95, 91, 94],
    },
  ]}
  curve="monotone"
  showYAxis
  showArea
  yAxis={{
    showGrid: true,
    label: 'Performance Score',
  }}
  renderPoints={({ dataX, dataY }) => {
    const isHighPerformance = dataY >= 90;
    const isLowPerformance = dataY < 75;

    return {
      fill: isHighPerformance
        ? 'var(--color-bgPositive)'
        : isLowPerformance
          ? 'var(--color-bgNegative)'
          : 'var(--color-fgPrimary)',
      radius: isHighPerformance ? 6 : 4,
      strokeWidth: 2,
      stroke: 'var(--color-bg)',
      label: isHighPerformance || isLowPerformance ? `${dataY}%` : undefined,
      labelProps: {
        verticalAlignment: isHighPerformance ? 'bottom' : 'top',
        dy: isHighPerformance ? -10 : 10,
        color: isHighPerformance
          ? 'var(--color-fgPositive)'
          : isLowPerformance
            ? 'var(--color-fgNegative)'
            : undefined,
      },
    };
  }}
/>

Is this page useful?

Coinbase Design is an open-source, adaptable system of guidelines, components, and tools that aid the best practices of user interface design for crypto products.