Blazor Chart Cursor Offset

TeeChart for JavaScript for the HTML5 Canvas
Post Reply
dynamicrisk
Newbie
Newbie
Posts: 23
Joined: Thu Apr 06, 2023 12:00 am

Blazor Chart Cursor Offset

Post by dynamicrisk » Wed Nov 20, 2024 10:39 pm

Hello,
I have a chart being in rendered into the following canvas.

Code: Select all

<tally-chart>
	<canvas id="canvas1" height="500" style="border: 0px solid #808080;" oncl />
</tally-chart>
I am trying to get my chart to extended to the end of my window without hard coding in a width.

I currently have width set to 100% as follows.

Code: Select all

tally-chart {
    display: flex;
    width: 100%;
    padding: 0;
    border: none;
    margin: 0;
    height: 500px
}

tally-chart > canvas {
    display: flex;
    width: inherit;
    height: inherit
}
An issue I am having though is the further I move my mouse cursor to the right, the more the chart thinks it is offset. I believe what is happening is the chart image is rendering into the canvas, and then the canvas is stretching to fill the screen. As a result it looks the chart doesn't recognize the correct location of the cursor. Is there a work around for this?

Thanks
Attachments
Screenshot (4).png
Screenshot (4).png (48.38 KiB) Viewed 1400 times
Screenshot (2).png
Screenshot (2).png (46.66 KiB) Viewed 1400 times

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Blazor Chart Cursor Offset

Post by Marc » Fri Nov 22, 2024 11:18 am

Hello,

Dynamic resizing of the Chart can be managed via a resize method such as used here:

https://www.steema.com/files/public/tee ... /lines.htm

(resize window to see chart sizing)

See the call:

Code: Select all

resize(Chart1);
code (in demo.js):

Code: Select all

function resize(element) {
  if (element != null) {
    var w = 0, xContent, canvas, chart;

    if (element instanceof HTMLCanvasElement) {
      canvas = element;

      if (canvas.chart instanceof Tee.Chart) {
        chart = canvas.chart;

        xContent = $(canvas).closest('.x_content')[0];
        w = parseFloat(window.getComputedStyle(xContent, null).width) | w;

        canvas.width = w;
        chart.bounds.width = w;
        chart.draw();
      }
    }
  }
}
You may be able to use this code, adapted to your needs.

Regards,
Marc Meumann
Steema Support

Post Reply