본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Tooltips

원문 보기 위키 갱신

차트 툴팁(Tooltips) 문서는 차트에 툴팁을 추가하는 방법을 다뤄요. voronoi 컨테이너, 커서 결합, 임베디드 범례·HTML, 고정 툴팁, 범례 툴팁 등 다양한 예시를 제공해요.

출처: 문서

본문

Introduction

Note: PatternFly React charts live in its own package at @patternfly/react-charts! 아래 예시들은 Victory 차트 라이브러리를 기반으로 하며, PatternFly를 위한 추가 기능, 사용자 지정 컴포넌트, 테마가 함께 포함되어 있어요. 이를 통해 일관된 마크업, 스타일, 동작으로 PatternFly 패턴을 만들 수 있는 React 기반 컴포넌트 모음을 제공해요.

Examples

Voronoi container

이 예시는 voronoi 컨테이너를 사용해 툴팁을 표시하는 방법을 보여줘요.

Area chart example chart titleAverage number of pets - possibly more information to summarize the data in the chart.

  • 2015
  • 2016
  • 2017
  • 2018
  • 2019
  • 2
  • 4
  • 6
  • 8CatsDogsBirds

Combined cursor and voronoi containers

이 예시는 커서와 voronoi 컨테이너를 결합해 수직 커서와 함께 툴팁을 표시하는 방법을 보여줘요.

Line chart example chart titleAverage number of pets - possibly more information to summarize the data in the chart.

  • 2015
  • 2016
  • 2017
  • 2018
  • 2
  • 5
  • 8CatsDogsBirdsMice

Embedded legend

이 예시는 툴팁 안에 범례를 임베드하는 방법을 보여줘요. 수직 커서와 함께 툴팁을 표시하려면 커서와 voronoi 컨테이너를 결합해야 해요.

Embedded legend example chart titleAverage number of pets - possibly more information to summarize the data in the chart.

  • 2015
  • 2016
  • 2017
  • 2018
  • 2
  • 5
  • 8CatsDogsBirdsMice

Embedded HTML

이 예시는 툴팁 안에 HTML을 임베드하는 방법을 보여줘요. 수직 커서와 함께 툴팁을 표시하려면 커서와 voronoi 컨테이너를 결합해야 해요.

Embedded html example chart titleAverage number of pets - possibly more information to summarize the data in the chart.

  • 2015
  • 2016
  • 2017
  • 2018
  • 2019
  • 2
  • 4
  • 6
  • 8CatsDogsBirds

Embedded legend with custom font size

이 예시는 툴팁 안에 범례를 임베드하되 사용자 지정 글꼴 크기를 사용하는 방법을 보여줘요. 수직 커서와 함께 툴팁을 표시하려면 커서와 voronoi 컨테이너를 결합해야 해요.

Embeded legend with custom font size example chart titleAverage number of pets - possibly more information to summarize the data in the chart.

  • 2015
  • 2016
  • 2017
  • 2018
  • 2
  • 5
  • 8CatsDogsBirdsMice

Data label

이 예시는 데이터 라벨을 사용해 툴팁을 적용하는 대체 방법을 보여줘요.

Data label example chart titleAverage number of pets - possibly more information to summarize the data in the chart.

  • 2015
  • 2016
  • 2017
  • 2018
  • 5
  • 10
  • 15
  • 20
  • 25CatsDogsBirdsMice

Fixed tooltip

이 예시는 툴팁 위치와 라벨 반경을 조정하는 방법을 보여줘요.

Donut chart exampleAverage number of pets100Pets

Legend

이 예시는 사용자 지정 범례 라벨 컴포넌트를 사용해 범례에 툴팁을 적용하는 방법을 보여줘요.

Legend example chart titleAverage number of pets - possibly more information to summarize the data in the chart.Cats: 35Dogs: 55Birds: 10

Left aligned

이 예시는 테마 속성을 사용해 툴팁 라벨 정렬을 사용자 지정하는 방법을 보여줘요.

Left aligned example chart titleAverage number of pets - possibly more information to summarize the data in the chart.

  • 2015
  • 2016
  • 2017
  • 2018
  • 2
  • 5
  • 8CatsDogsBirdsMice

CSS overflow

이 예시는 constrainToVisibleArea 대신 CSS overflow를 사용해 툴팁을 적용하는 대체 방법을 보여줘요.

CSS overflow example chart titleAverage number of pets - possibly more information to summarize the data in the chart.CPU utilization

Wrapped chart

이 예시는 Tooltip 컴포넌트로 차트를 감싸 툴팁을 적용하는 대체 방법을 보여줘요.

Wrapped example chart titleStorage capacity - possibly more information to summarize the data in the chart.45%of 100 GBps

Documentation

Tips

  • Victory의 FAQ를 참고하세요.

Note

현재 아래에 생성된 문서는 Victory import의 타입 정의를 해석하지 못해요. 위 예시에서 사용된 컴포넌트의 Victory pass-thru 속성도 여기에 문서화되어 있어요.

Props

ChartTooltip

ChartTooltip은 기본 이벤트 집합이 포함된 툴팁 컴포넌트를 렌더링해요. ChartTooltip을 데이터를 렌더링하는 어떤 Victory 기반 컴포넌트의 라벨 컴포넌트로 사용하면, 렌더링된 데이터 컴포넌트에 이벤트를 연결해 호버하거나 포커스할 때 툴팁을 활성화해요. ChartTooltipTooltip은 텍스트와 구성 가능한 Flyout 컨테이너를 렌더링해요.

Note: ChartLine이나 ChartArea에 툴팁을 제공할 때는 ChartVoronoiContainer를 사용해야 해요. 이 컴포넌트들은 전체 데이터셋에 대해 단일 요소만 렌더링하기 때문이에요.

See https://github.com/FormidableLabs/victory/blob/main/packages/victory-tooltip/src/index.d.ts

*required | | Name | Type | Default | Description | activateData | boolean | | When true, tooltip events will set the active prop on both data and label elements. | | active | boolean | | The active prop specifies whether the tooltip component should be displayed. | | angle | number | | The angle prop specifies the angle to rotate the tooltip around its origin point. | | center | { x: number; y: number } | | The center prop determines the position of the center of the tooltip flyout. This prop should be given as an object that describes the desired x and y svg coordinates of the center of the tooltip. This prop is useful for positioning the flyout of a tooltip independent from the pointer. When ChartTooltip is used with ChartVoronoiContainer, the center prop is what enables the mouseFollowTooltips option. When this prop is set, non-zero pointerLength values will no longer be respected. | | centerOffset | { x: number | Function, y: number | Function } | | The centerOffset prop determines the position of the center of the tooltip flyout in relation to the flyout pointer. This prop should be given as an object of x and y, where each is either a numeric offset value or a function that returns a numeric value. When this prop is set, non-zero pointerLength values will no longer be respected. | | constrainToVisibleArea | boolean | false | The constrainToVisibleArea prop determines whether to coerce tooltips so that they fit within the visible area of the chart. When this prop is set to true, tooltip pointers will still point to the correct data point, but the center of the tooltip will be shifted to fit within the overall width and height of the svg Victory renders. | | cornerRadius | number | Function | | The cornerRadius prop determines corner radius of the flyout container. This prop may be given as a positive number or a function of datum. | | data | any[] | | Victory components can pass a data prop to their label component. This can be useful in custom components that need to make use of the entire dataset. | | datum | {} | | Victory components can pass a datum prop to their label component. This can be used to calculate functional styles, and determine text. | | dx | number | Function | | The dx prop defines a horizontal shift from the x coordinate. | | dy | number | Function | | The dy prop defines a vertical shift from the y coordinate. | | events | object | | The events prop attaches arbitrary event handlers to the label component. This prop should be given as an object of event names and corresponding event handlers. When events are provided via Victory’s event system, event handlers will be called with the event, the props of the component is attached to, and an eventKey. | @example events={{onClick: (evt) => alert("x: " + evt.clientX)}}

| flyoutComponent | React.ReactElement | | The flyoutComponent prop takes a component instance which will be used to create the flyout path for each tooltip. The new element created from the passed flyoutComponent will be supplied with the following properties: x, y, dx, dy, index, datum, cornerRadius, pointerLength, pointerWidth, width, height, orientation, style, and events. Any of these props may be overridden by passing in props to the supplied component, or modified or ignored within the custom component itself. If flyoutComponent is omitted, a default Flyout component will be created with props described above. | @example flyoutComponent={}, flyoutComponent={}

| flyoutHeight | number | Function | | The flyoutHeight prop defines the height of the tooltip flyout. This prop may be given as a positive number or a function of datum. If this prop is not set, height will be determined based on an approximate text size calculated from the text and style props provided to ChartTooltip. | | flyoutStyle | number | Function | | The style prop applies SVG style properties to the rendered flyout container. These props will be passed to the flyoutComponent. | | flyoutWidth | number | Function | | The flyoutWidth prop defines the width of the tooltip flyout. This prop may be given as a positive number or a function of datum. If this prop is not set, flyoutWidth will be determined based on an approximate text size calculated from the text and style props provided to VictoryTooltip. | | groupComponent | React.ReactElement | | The groupComponent prop takes a component instance which will be used to create group elements for use within container elements. This prop defaults to a tag.} | | horizontal | boolean | | The horizontal prop determines whether to plot the flyouts to the left / right of the (x, y) coordinate rather than top / bottom. This is useful when an orientation prop is not provided, and data will determine the default orientation. i.e. negative values result in a left orientation and positive values will result in a right orientation by default. | | index | number | string | | The index prop represents the index of the datum in the data array. | | labelComponent | React.ReactElement | | The labelComponent prop takes a component instance which will be used to render each tooltip label. The new element created from the passed labelComponent will be supplied with the following properties: x, y, index, datum, verticalAnchor, textAnchor, style, text, and events. Any of these props may be overridden by passing in props to the supplied component, or modified or ignored within the custom component itself. If labelComponent is omitted, a new ChartLabel will be created with the props described above. | @example labelComponent={}, labelComponent={}

| labelTextAnchor | string | Function | | Defines how the labelComponent text is horizontally positioned relative to its x and y coordinates. Valid values are 'start', 'middle', 'end', and 'inherit'. | | orientation | string | Function | | The orientation prop determines which side of the (x, y) coordinate the tooltip should be rendered on. This prop can be given as “top”, “bottom”, “left”, “right”, or as a function of datum that returns one of these values. If this prop is not provided it will be determined from the sign of the datum, and the value of the horizontal prop. | | pointerLength | number | Function | | The pointerLength prop determines the length of the triangular pointer extending from the flyout. This prop may be given as a positive number or a function of datum. | | pointerOrientation | string | Function | | This prop determines which side of the tooltip flyout the pointer should originate on. When this prop is not set, it will be determined based on the overall orientation of the flyout in relation to its data point, and any center or centerOffset values. Valid values are 'top', 'bottom', 'left' and 'right. | | pointerWidth | number | Function | | The pointerWidth prop determines the width of the base of the triangular pointer extending from the flyout. This prop may be given as a positive number or a function of datum. | | renderInPortal | boolean | | When renderInPortal is true, rendered tooltips will be wrapped in VictoryPortal and rendered within the Portal element within ChartContainer. Note: This prop should not be set to true when using a custom container element. | | style | React.CSSProperties | React.CSSProperties[] | | The style prop applies CSS properties to the rendered <text> element. | | text | number | string | Function | string[] | number[] | | The text prop defines the text ChartTooltip will render. The text prop may be given as a string, number, or function of datum. When ChartLabel is used as the labelComponent, strings may include newline characters, which ChartLabel will split in to separate elements. | | theme | object | getTheme(themeColor) | The theme prop specifies a theme to use for determining styles and layout properties for a component. Any styles or props defined in theme may be overwritten by props specified on the component instance. | | themeColor | string | | Specifies the theme color. Valid values are 'blue', 'green', 'multi', etc. | Note: Not compatible with theme prop

@example themeColor={ChartThemeColor.blue}

| x | number | | The x prop defines the x coordinate to use as a basis for horizontal positioning. | | y | number | | The y prop defines the y coordinate to use as a basis for vertical positioning. |

Edit this page on GitHub

더 알아보기 (Learn more)