Pre loader

Unexpected Double Rendering and Chart Disappearance in Multi-Pane SciChart with Next.js

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

1
0

enter image description here

Hi everyone,

I’m working on a multi-pane chart using JavaScript and Next.js based on the SciChart.JS Examples((https://github.com/ABTSoftware/SciChart.JS.Examples/blob/master/Examples/src/components/Examples/Charts2D/CreateStockCharts/MultiPaneStockCharts/drawExample.ts). I’m experiencing an intermittent issue related to double rendering that I haven’t been able to track down.

Issue Details:
• Symptom:
• Before Data Loads: I see a double set of loading spinners.
• After Data Loads: The chart disappears entirely.
• Environment Variability:
• The issue appears to be environment-specific. For example:
• It works as expected in my development Chrome browser.
• In Safari, the chart either doesn’t render or behaves inconsistently.
• The bug occurs in both the deployed version on Vercel and on localhost.
• At one point, a colleague reported it not working in Chrome browser, but later it seemed to work—so the behavior is not consistently reproducible.

Tech Stack:
• Next.js with TypeScript
• Vercel deployment
• SciChart version: “scichart”: “^3.5.711”
• SciChart React version: “scichart-react”: “^0.1.9”

Relevant Code Snippet:

 

{/* Price Chart */}
<SciChartReact
initChart={chartsInitializationAPI.drawPriceChart}
style={{ flexBasis: 400, flexGrow: 1, flexShrink: 1 }}
/>
{/* OHLC Chart */}

{/* RSI Chart */}

{/* Z-Score Chart */}

 

Questions:
1. What could be causing the component to double-render and then eventually make the chart disappear?
2. How can I isolate the cause (e.g., determining if it’s due to React Strict Mode, asynchronous updates, or some other side effect)?

Any insights or suggestions on how to debug and resolve this issue would be greatly appreciated!

Thanks in advance!

Version
3.5.711
  • You must to post comments
1
0

Hello,

Thanks for the feedback.

Unfortunately, adding loader: false does not resolve the issue.

However, the strange thing is that it still shows a single loader. It seems that the chart is being initialized twice.

The tricky part is that this happens in some environments but not in others.

It is not related to deployment status or browser type. For example, the chart displays correctly on a laptop but not on a mobile device.

But on same device, it works on chrome but not from safari.

  • You must to post comments
0
0

Hello,
If I understood correctly, this issue occurs both in developement and production mode (with StrictMode disabled), right?
I think the following will help: set “loader: false” via creation options for each of the charts

SciChartSurface.create(root, {
  // ...
  loader: false
})
  • You must to post comments
0
0

Hello, we need to understand what your setup looks like.
And what is the exact issue: is your chart being initialized twice or are there just redundant loaders?

To check whether a chart is being initialized twice, you can just add some logging to the init function you pass into SciChartReact (or enable SciChart internal logs via Logger.enableDebug = true before chart creation).
Otherwise, if the issue is just in some redundant loaders, compare it to the number of charts you create.
And let us know whether you are using the SciChartNestedOverview component.
So please provide more info if nothing of the following helps.

We have updated our demo website recently and there might be some changes to the demos.
Check out the example code here again.

Now it uses a custom component (ChartGroupLoader) to show a single spinner over multiple charts.

FYI, to set a loader on the SciChartReact component you pass the “fallback” property.

Thus, to sum up:
– check whether a specific chart is being initialized multiple times
– set “loader: false” when creating a chart (including the Overview component since it is technically a separate chart). This disables the native HTML loader of the core lib
– try changing the “fallback” property on SciChartReact. It specifies a React component used as a loader. (default – )
– check out as an example of adding a single loader over multiple charts.

Then, let us know what is your progress with that.

  • You must to post comments
0
0

First of all, thanks for the reply and your attention to this issue.

You can refer to the gist that include all the code related to the chart.

https://gist.github.com/posgnu/aaa041b43c967a254cd4b112b2602338

  1. To check if the chart is initialized twice

I have put logging on two parts

      <SciChartGroup onInit={() => {
    console.log("Initializing SciChartGroup");
    chartsInitializationAPI.syncAxes();
    updateChartData();
  }}>

and

  useEffect(() => {
if (chartsInitializationAPI === null) {
  if (!isKpLoading && !isFxLoading && !isUsdtLoading && !isBtcLoading) {
    console.log("Initializing SciChartGroup");
    setChartsInitializationAPI(
      getChartsInitializationAPI(setCurrentStartTime),
    );
  }

but the log was only printed once.

I have also added logging in front of each SciChartSurface.create call of every children chart like below

    console.log("Drawing Price Chart");
const { wasmContext, sciChartSurface } = await SciChartSurface.create(
  rootElement,
  {
    disableAspect: true,
    theme: chartTheme.SciChartJsTheme,
  },
);

It is still printed once.

  1. I am not using SciChartNestedOverview

  2. I am not adding or customizing any loaders. They are all default loaders.

Thanks again for your support.

  • You must to post comments
0
0

New update.

it is working well if I remove this from each chart creation.

//        disableAspect: true,

However, it breaks the ratio of the height of each chart I set here

          <SciChartReact
        initChart={chartsInitializationAPI.drawOhlcChart}
        style={{ flexBasis: 200, flexGrow: 1, flexShrink: 1 }}
      />
  • You must to post comments
0
0

It is working nicely after I replace flexbasis with height

return (
<div className="flex flex-col gap-1 w-full items-center">
  <ControlSection
    timeFrame={timeFrame}
    setTimeFrame={setTimeFrame}
    zoomToFullRange={chartsInitializationAPI.zoomToFullRange}
  />

  <SciChartGroup onInit={() => {
    chartsInitializationAPI.syncAxes();
    updateChartData();
  }}>
    <div
      className="w-full"
      style={{ display: "flex", flexDirection: "column", height: "100%" }}
    >
      {/* Price Chart */}
      <SciChartReact<SciChartSurface>
        initChart={chartsInitializationAPI.drawPriceChart}
        style={{ height: 400, flexGrow: 1, flexShrink: 1 }}
      />
      {/* OHLC Chart */}
      <SciChartReact
        initChart={chartsInitializationAPI.drawOhlcChart}
        style={{ height: 200, flexGrow: 1, flexShrink: 1 }}
      />
      {/* BTC OHLC Chart */}
      <SciChartReact
        initChart={chartsInitializationAPI.drawBtcOhlcChart}
        style={{ height: 200, flexGrow: 1, flexShrink: 1 }}
      />
      {/* RSI Chart */}
      <SciChartReact
        initChart={chartsInitializationAPI.drawRsiChart}
        style={{ height: 100, flexGrow: 1, flexShrink: 1 }}
      />
      <SciChartReact
        initChart={chartsInitializationAPI.drawZScoreChart}
        style={{ height: 100, flexGrow: 1, flexShrink: 1 }}
      />
    </div>
  </SciChartGroup>
</div>

);

Would it be possible to get some explanation about this error so that I do not repeat in the future?

  • You must to post comments
Showing 6 results
Your Answer

Please first to submit.