chart.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {useTheme} from '@emotion/react';
  2. import {AreaChart} from 'sentry/components/charts/areaChart';
  3. import {axisLabelFormatter, getDurationUnit} from 'sentry/utils/discover/charts';
  4. import {getDuration} from 'sentry/utils/formatters';
  5. type Props = React.ComponentPropsWithoutRef<typeof AreaChart>;
  6. function Chart(props: Props) {
  7. const theme = useTheme();
  8. const durationUnit = getDurationUnit(props.series);
  9. return (
  10. <AreaChart
  11. grid={{left: '10px', right: '10px', top: '40px', bottom: '0px'}}
  12. xAxis={{
  13. type: 'category' as const,
  14. truncate: true,
  15. axisLabel: {
  16. showMinLabel: true,
  17. showMaxLabel: true,
  18. },
  19. axisTick: {
  20. interval: 0,
  21. alignWithLabel: true,
  22. },
  23. }}
  24. yAxis={{
  25. minInterval: durationUnit,
  26. type: 'value' as const,
  27. axisLabel: {
  28. color: theme.chartLabel,
  29. // Use p50() to force time formatting.
  30. formatter: (value: number) =>
  31. axisLabelFormatter(value, 'duration', undefined, durationUnit),
  32. },
  33. }}
  34. tooltip={{valueFormatter: value => getDuration(value / 1000, 2)}}
  35. {...props}
  36. />
  37. );
  38. }
  39. export default Chart;