Skip to content

Commit 1cfc9f8

Browse files
authored
Docs: Add Brush and Zoom sample to Candlestick chart (#2982)
1 parent 95d35f3 commit 1cfc9f8

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

website/docs/charts/candlestick.mdx

+94
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,100 @@ Events can be handled by passing an array of event objects to the `events` prop
502502
</VictoryChart>
503503
```
504504

505+
## Candlestick - Brush and Zoom
506+
507+
Candlestick charts support zoom and pan behavior by using the `VictoryZoomContainer` and `VictoryBrushContainer` components. See the [Brush & Zoom](/docs/guides/brush-and-zoom) guide for more information.
508+
509+
```jsx live noInline
510+
function App() {
511+
const sampleData = [
512+
{
513+
x: 5,
514+
open: 5,
515+
close: 10,
516+
high: 15,
517+
low: 0,
518+
},
519+
{
520+
x: 10,
521+
open: 10,
522+
close: 15,
523+
high: 20,
524+
low: 5,
525+
},
526+
{
527+
x: 15,
528+
open: 15,
529+
close: 20,
530+
high: 22,
531+
low: 10,
532+
},
533+
{
534+
x: 20,
535+
open: 20,
536+
close: 10,
537+
high: 25,
538+
low: 7,
539+
},
540+
{
541+
x: 25,
542+
open: 10,
543+
close: 8,
544+
high: 15,
545+
low: 5,
546+
},
547+
];
548+
const [state, setState] = React.useState({});
549+
550+
const handleZoom = (domain) => {
551+
setState({ selectedDomain: domain });
552+
};
553+
554+
const handleBrush = (domain) => {
555+
setState({ zoomDomain: domain });
556+
};
557+
558+
return (
559+
<div>
560+
<VictoryChart
561+
theme={VictoryTheme.clean}
562+
domainPadding={{ x: 25 }}
563+
containerComponent={
564+
<VictoryZoomContainer
565+
zoomDimension="x"
566+
zoomDomain={state.zoomDomain}
567+
onZoomDomainChange={handleZoom}
568+
/>
569+
}
570+
>
571+
<VictoryCandlestick
572+
data={sampleData}
573+
/>
574+
</VictoryChart>
575+
576+
<VictoryChart
577+
height={170}
578+
theme={VictoryTheme.clean}
579+
domainPadding={{ x: 25 }}
580+
padding={{top: 0, left: 50, right: 50, bottom: 30}}
581+
containerComponent={
582+
<VictoryBrushContainer
583+
brushDimension="x"
584+
brushDomain={state.selectedDomain}
585+
onBrushDomainChange={handleBrush}
586+
/>
587+
}
588+
>
589+
<VictoryAxis />
590+
<VictoryCandlestick data={sampleData} />
591+
</VictoryChart>
592+
</div>
593+
)
594+
}
595+
596+
render(<App />);
597+
```
598+
505599
## Standalone Rendering
506600

507601
Box Plot charts can be rendered outside a VictoryChart.

0 commit comments

Comments
 (0)