0
 $.ajax({
    type : type,

    data: form_data,
    url : geturl(a),

    dataType : 'json',

    error : function(result) {
         alert("error");
        // alert("Error occured!!");

    },

    success : function(result,data) 
    { 
    var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container',
        type: 'line',
            marginRight: 300,
            marginBottom: 75,
            marginLeft:50,
            marginTop:80

    },
    title: {
        marginTop:100,
        text:' True Power '
    },
    xAxis: {

        categories: result[0]

    },

    yAxis: {
        title: {
            text: 'Units Of Time'
        }
    },


});

}

    }) 



      }


$(function(){
$('#b').click( function(event) {
event.preventDefault();
alert("tgg");

 chart.setTitle = ({text:"Power Factor"});

 });
 });

when i click on this anchor tag the title should change, i have set a id="b" as below POWERFACTOR

but it gives e error saying chart not defined. could u help lik how to change the title and also the series

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
prithu
  • 103
  • 3
  • 7
  • 2
    `chart` is only **local** to the `success` callback. You have to declare it in a scope where it can be seen by both, the `success` callback and the click event handler. – Felix Kling Feb 22 '13 at 13:26
  • could u tell me how to eclare it again. – prithu Feb 22 '13 at 13:33
  • 1
    You declare a variable with `var variableName;`, just like you did in the success callback. But you have to declare it *outside* the success callback. Maybe this helps you to understand how scope works: http://stackoverflow.com/questions/500431/javascript-variable-scope/500459. – Felix Kling Feb 22 '13 at 13:34
  • i gave it inside the function click as var chart = new Highcharts.Chart but it gives me the error saying "Cannot read property 'series' of undefined " – prithu Feb 22 '13 at 13:41

1 Answers1

2

Have you seen this example: http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/members/chart-settitle/ from documentation ?

$('#title').click(function () {
    chart.setTitle({
        text: 'New title '
    });
});
Sebastian Bochan
  • 37,348
  • 3
  • 49
  • 75