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 6702553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:04:02+00:00 2026-05-26T07:04:02+00:00

I am attempting to generate a custom tooltip using Microsoft Chart Controls. Microsoft Chart

  • 0

I am attempting to generate a custom tooltip using Microsoft Chart Controls. Microsoft Chart Controls supports the ability to use keywords which helps automate the data you wish to display.

For example,

string toolTip = string.Format("<div> {0}: {1} {3} ({2}) </div>", seriesName, "#VALY", "#VALX", "<br>");
series.MapAreaAttributes = "onfocus=\"if(this.blur)this.blur();\" onmouseover=\"DisplayTooltip('" + JavaScriptStringLiteral(toolTip) + "');\" onmouseout=\"DisplayTooltip('');\"";

In the above code, "#VALY" and "#VALX" are keywords. At run time, these keywords are replaced with actual values. In my scenario, #VALY is a double and #VALX is a date-time.

Observe:

Enter image description here

Now, this works perfectly fine if I use the data series’ tooltip property. Unfortunately, Firefox and Opera do not (easily) support multi-line tooltips. I am attempting to illicit this feature out of them by using Custom Tooltips.

As such, I have the onmouseover and onmouseout code — this is JavaScript code which is responsible for the tooltip.

The problem is that when #VALX is evaluated it contains illegal JavaScript characters. This causes the error message "Uncaught SyntaxError: Unexpected token ILLEGAL"

Note that I have wrapped the tooltip with the method JavaScriptStringLiteral. Here is the utility function:

private static readonly Regex scriptTagRegex = new Regex("script", RegexOptions.IgnoreCase | RegexOptions.Multiline);

    /// <summary>
    ///     Processes the provided string, creating a quoted JavaScript string literal.
    /// </summary>
    /// <param name="str">The string to process</param>
    /// <returns>A string containing a quoted JavaScript string literal</returns>
    public static string JavaScriptStringLiteral(string str)
    {
        var sb = new StringBuilder();
        sb.Append("\"");
        foreach (char c in str)
        {
            switch (c)
            {
                case '\"':
                    sb.Append("\\\"");
                    break;
                case '\\':
                    sb.Append("\\\\");
                    break;
                case '\b':
                    sb.Append("\\b");
                    break;
                case '\f':
                    sb.Append("\\f");
                    break;
                case '\n':
                    sb.Append("\\n");
                    break;
                case '\r':
                    sb.Append("\\r");
                    break;
                case '\t':
                    sb.Append("\\t");
                    break;
                default:
                    int i = (int)c;
                    if (i < 32 || i > 127)
                    {
                        sb.AppendFormat("\\u{0:X04}", i);
                    }
                    else
                    {
                        sb.Append(c);
                    }
                    break;
            }
        }
        sb.Append("\"");

        // If a JavaScript tag contains "</script>", then it terminates a
        // script block.  Start by replacing each 's'/'S' with an escape
        // sequence so it doesn't trigger this.
        return scriptTagRegex.Replace(
            sb.ToString(),
            m => (m.Value[0] == 's' ? "\\u0073" : "\\u0053") + m.Value.Substring(1));
    }

If #VALX was not run-time evaluated, I believe this utility method would solve my issue. But, as such, the utility function evalutes "#VALX" as a string literal. Then, after filtering no illegal characters, #VALX is evaluated and places illegal characters into my JavaScript.

Is there a way of preventing this issue? Something equivalent to the "@" character for paths in C#?


I figured out the solution and it is dumb.

foreach (HistoricalDataValue value in data)
{
    series.Points.AddXY(string.Format("{0:d}{1}{0:T}", value.TimeStamp, "\\n"), value.AttributeValue);
}

Note that this says "\\n". This used to say Environment.NewLine, but this does not work. In addition, if you use Environment.NewLine -or- "\n" you can’t edit "#VALX" later because of run time evaluation. Thus, you have to use an escaped out newline when adding the X value, so that when #VALX gets it it is already formatted properly.

  • 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-26T07:04:02+00:00Added an answer on May 26, 2026 at 7:04 am

    When you call the JavaScriptStringLiteral your code already opened a single-quote string, while that function returns a string already wrapped in double quotes.

    You should strip first and last character from what JavaScriptStringLiteral returns.

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

Sidebar

Related Questions

I am attempting to build a simple WPF Application using msbuild via a custom
I'm attempting to generate artifacts for the following amazon wsdl: http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl using the following
I am attempting to dynamically generate cube-maps in OpenGL using a multi-pass rendering system.
I'm using JLex for our latest assignment, attempting to generate a scanner for a
I am attempting to generate a dOOdads business entity using MyGeneration against an Oracle
I'm attempting to run TextTransform.exe to generate code using a T4 template file. The
I am attempting to use faceting to generate multiple maps filled with different values.
I was attempting to use ObjectIDGenerator in C# to generate a unique ID during
I am attempting to generate datamatrix barcodes from within itext. This works fine for
I am attempting to generate a BitmapFrame that is based on a UIElement .

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.