0

How do you wrap a function ?

i have asked this before, but am trying to make this question as simple as possible.

So this is the code I need to wrap :

$(function () { 
$('#container').highcharts({
chart: {
    type: 'bar'
},
title: {
    text: 'Fruit Consumption'
},
xAxis: {
    categories: ['Apples', 'Bananas', 'Oranges']
},
yAxis: {
    title: {
        text: 'Fruit eaten'
    }
},
series: [{
    name: 'Jane',
    data: [1, 0, 4]
}, {
    name: 'John',
     data: [5, 7, 3]
 }]
 });
 });​

div:

<div id="container" style="width:340px; height:270px;"></div>

I was told I can put this into a wrap and then call the function. How can this be done?

This data is dummy, my data is coming from the server. What i want is to redraw the chart in code behind so it refreshes the data, using RegisterClientScriptBlock.

but for this, i first need to wrap the function...

i have this, but get error:

    Dim someScript As String = "<script language='javascript'>container1_highcharts();</script>"
    Page.ClientScript.RegisterStartupScript(Me.[GetType](), "onload", someScript)

error:

  Uncaught ReferenceError: container_highcharts is not defined 

2 Answers 2

1

this is what you need:

protected void Page_Load(object sender, EventArgs e){
 string someScript = "<script language='javascript'>container_highcharts();</script>";
 Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", someScript);
}
Sign up to request clarification or add additional context in comments.

Comments

0
var container1_highcharts = function() {
    this.chart = new HighCharts.Chart(options);
}
// then call
var chart = new container1_highcharts();

see some jsfiddle here: http://jsfiddle.net/kreeg/gPAJa/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.