Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7406307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:32:16+00:00 2026-05-29T05:32:16+00:00

I am developing a WebPart in SharePoint,and I need to draw something in my

  • 0

I am developing a WebPart in SharePoint,and I need to draw something in my WebPart using excanvas.js.But sometimes it shows nothing.The error message is:

Object doesn't support property or method 'getContext'

When I debug it,it breaks at here:

var ctxBg = document.getElementById(backgroundId).getContext("2d");

The “backgroundId” is the id of one canvas element.
This error happens not every times,just sometimes,so I think if my js function is executed before the excanvas.js is loaded.I register the excanvas.js with the code:

this.Page.ClientScript.RegisterClientScriptInclude("ExCanvasJs", "wpresources/MyWebPart/js/excanvas.js");

So how to ensure my function is executed after the excanvas.js is loaded?Or I’m wrong at this problem?Would you give me your advice?

my js function:

function DrawMeter(meter, contextCollection) {
var backgroundId = meter.meterbackground;
var pointerId = meter.meterpointer;
var containerId = meter.metercontainer;
if (contextCollection != null && contextCollection.length > 0) {
    for (var i = 0; i < contextCollection.length; i++) {                    
        DrawSingleMeter(backgroundId + "_" + i, pointerId + "_" + i, containerId + "_" + i, contextCollection[i]);
    }
}

function DrawSingleMeter(backgroundId, pointerId, containerId, context) {
var ctxBg = document.getElementById(backgroundId).getContext("2d");
var ctxPointer = document.getElementById(pointerId).getContext("2d");
drawing...

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:32:17+00:00Added an answer on May 29, 2026 at 5:32 am

    you need to put it into a page ready handler. otherwise at the time the javascript is executed the element might not be available yet.
    consider using jquery or another js library for this, if you can’t use it here’s a link on how to use the native js version of the onload event

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a custom webpart for SharePoint 2007 using C# and Visual Studio. I
I am developing a webpart in SharePoint. I am using windows authentication for logging
Currently I’m developing a webpart for SharePoint. I’m using JQuery in my webpart. Users
I am developing a WebPart (it will be used in a SharePoint environment, although
My current project for work involves developing a SharePoint 2007 WebPart which will be
I am developing a webpart using VSTS 2008 + C# + .Net 3.5 +
I am currently developing a sharepoint webpart to display a private discussion board. The
I am developing one sharepoint webpart, in this i have 2 date time control,
I'm developing a webpart in Visual Studio 2010 for SharePoint 2010, and I would
I'm creating a specific webpart in Sharepoint and I'm using (or trying to) AjaxToolkit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.