[英]Styling HighCharts reset Zoom button with Material UI button
I'm working on a project where we're using HighCharts and Material UI for UI components.我正在开发一个项目,我们正在使用 HighCharts 和 UI 组件的 Material UI。 Is there any way I can use the Material UI button component in place of the standard HighChart reset Zoom button?
有什么方法可以使用 Material UI 按钮组件代替标准的 HighChart 重置缩放按钮?
This button has limited styling options, but you can replace it by a custom one in simple steps:此按钮的样式选项有限,但您可以通过简单的步骤将其替换为自定义选项:
Highcharts.Chart.prototype.showResetZoom = function () {};
chart.zoomOut
method called on click:chart.zoomOut
方法:const App = () => {
const chartComponent = useRef(null);
const [isZoomed, setIsZoomed] = useState(false);
const [options] = useState({
chart: {
zoomType: "x",
events: {
selection: function (e) {
if (e.resetSelection) {
setIsZoomed(false);
} else {
setIsZoomed(true);
}
}
}
},
...
});
const resetZoom = () => {
if (chartComponent && chartComponent.current) {
chartComponent.current.chart.zoomOut();
}
};
return (
<div style={{ position: "relative" }}>
<HighchartsReact
ref={chartComponent}
highcharts={Highcharts}
options={options}
/>
{isZoomed && (
<Button
style={{ position: "absolute", top: 50, right: 10 }}
onClick={resetZoom}
color="primary"
>
Reset zoom
</Button>
)}
</div>
);
};
Live demo: https://codesandbox.io/s/highcharts-react-demo-forked-ssqk9?file=/demo.jsx现场演示: https://codesandbox.io/s/highcharts-react-demo-forked-ssqk9?file=/demo.jsx
API Reference: https://api.highcharts.com/class-reference/Highcharts.Chart#zoomOut API 参考: https://api.highcharts.com/class-reference/Highcharts.Chart#zoomOut
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.