Open a new window using MapAreaAttributes in micro

2019-09-18 18:01发布

i am using MS asp.net 3.5 chart control (Pyramid) and on the click of the series/datapoint i need to open a URL in a new window, something like javascript window.open.

Now i have tried a hell lot but that doesn't work. I am not able to give javascript to the datapoint.

Secondly i got to know that MapAreaAttributes could be given to Series as mentioned below if a new window needs to be open

series.MapAreaAttributes= "target='_blank'";

But even this doesn't works????

Guide me! Thanks

1条回答
Bombasti
2楼-- · 2019-09-18 18:48

I had your same problem just now.

Here is the solutions and it works:

Notice in your code that you're using the single quotation ('). It seems that this is not allowed by the chart control or something. Let me give you an example that might help you understand:

Let's assume you have a JavaScript function that opens a window showing some data when the user clicks on a column (point) in your data (series). You can do it like this:

Chart1.Series["MySeries"].Points[0].Url = "javascript:void(0)"; //this is just to tell the browser not follow a URL, since you will control this with your javascript

Chart1.Series["MySeries"].Points[0].MapAreaAttributes = "onclick=\"OpenWindow();\""; //this is to set the onclick attribute to fire your javascript function when the user clicks your column.

In the above example in the second line of code, notice that I have used double quotation instead of single ones. If you wrote it like this :

"onclick=\'OpenWindow();\'"; 

it will never work! You have to use double quotations...

Also, since I am a C# developer, you have to use the \" code to write double quotations otherwise, you will get compiler error.

I hope this helps!

查看更多
登录 后发表回答