【发布时间】:2021-08-30 12:19:20
【问题描述】:
我们在 React 中使用 highcharts 时遇到了一些问题。当我使用菜单按钮更改为全屏模式时,我看不到“从全屏退出”选项。相反,该选项仍然是“全屏查看”....但是,如果我单击此选项,它实际上会退出全屏模式。我希望能够看到文本“退出全屏”。我认为问题出在这段代码最后几行声明的事件中(exporting.chartOptions.chart)。
useEffect(() => {
const chart = chartRef?.current?.chart;
if (!chart?.renderer) return;
setChartOptions(({ chart, credits, legend, xAxis, yAxis, plotOptions, ...currentOptions }) => ({
...currentOptions,
chart: {
...chart,
...chartExtraOptions.current?.chart,
},
credits: {
...credits,
position: {
...credits?.position,
...chartExtraOptions.current?.credits.position,
},
},
legend: {
...legend,
...chartExtraOptions.current?.legend,
},
xAxis: {
...xAxis,
...chartData?.xAxis,
title: { text: undefined },
plotLines: [
{
value: ((chartData?.xAxis?.max ?? 0) + (chartData?.xAxis?.min ?? 0)) / 2,
color: "#84acbc",
},
],
},
yAxis: {
...yAxis,
...chartData?.yAxis,
title: { text: undefined },
plotLines: [
{
value: ((chartData?.yAxis?.max ?? 0) + (chartData?.yAxis?.min ?? 0)) / 2,
color: "#84acbc",
},
],
},
series: chartData?.series,
exporting: {
chartOptions: {
chart: {
events: {
load: function (this) {
chartAxesTitles.current.forEach((element) => {
const { args, attr, css } = element.svg.userOptions;
// Use updated x and y positions
const newArgs = [args[0], element.svg.x, element.svg.y];
createLabel(this.renderer, { args: newArgs, attr, css });
renderWatermarkLabels(this, true);
});
// console.log(this);
},
},
},
},
},
但我不知道为什么!有任何想法吗?谢谢!
如果有帮助,我会添加图表的配置:
import { WATERMARK } from "constants/chartCommons";
export const OPTIONS: Highcharts.Options = {
chart: {
className: "IndividualPositioningChart",
type: "scatter",
spacing: [0, 0, 0, 0],
},
credits: {
text: WATERMARK,
href: "#",
position: {
align: "left",
},
style: {
fontSize: "8px",
},
},
title: {
text: undefined,
},
xAxis: {
startOnTick: false,
lineWidth: 0,
tickColor: "transparent",
gridLineColor: "transparent",
labels: {
enabled: false,
},
},
yAxis: {
gridLineColor: "transparent",
labels: {
enabled: false,
},
},
legend: {
verticalAlign: "bottom",
itemWidth: 150,
margin: 20,
},
tooltip: {
snap: 1,
enabled: true,
backgroundColor: "black",
borderWidth: 0,
borderRadius: 2,
padding: 4,
shadow: false,
useHTML: true,
style: {
color: "white",
fontSize: "11px",
},
headerFormat: undefined,
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
y: 13,
x: 8,
align: "left",
useHTML: true,
padding: 5,
style: {
fontWeight: "normal",
fontSize: "14px",
color: "#515151",
width: 250,
},
},
stickyTracking: false,
},
},
series: [],
};
【问题讨论】:
-
嗨@CatroVal,请查看此示例:codesandbox.io/s/highcharts-react-demo-fork-guk4c?file=/… 和显示页面:guk4c.csb.app 如您所见,按钮显示正确的文本。该问题可能与使用
renderWatermarkLabels有关,它可以触发组件重新渲染。你能在codeandbox中重现这个问题吗?
标签: javascript reactjs typescript highcharts react-highcharts