Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HighCharts Dynamically Change Chart Type

Using HighCharts 2.2.3 in an ASP.NET site. See http://jsfiddle.net/wergeld/TDLvc/ for code example. My site setup is a little different than what the jsFiddle shows. My function to change the series exists in an included JS file and the call to the function is not "in-line" with the chart creation JS code (although it is still wrapped in a document ready jquery).

I have two issues and one of which can be seen in the jsFiddle. 1) When changing chart type it looks like the yAxis designation gets lost. You can see I have originally 2 yAxis and after you change the chart type the top axis no longer has value labels (means that the chart data is using only the bottom axis (first yAxis)). 2) When running this under FF or IE I get an error on the line that calls:

data: serie.options.data

The error is: c is not a constructor Line 55 in highcharts.js (this is the min-ed file).

Using highcharts.src.js I can now see that the error is: typeClass is not a constructor

This is on line 8789 in the src.js: serie = new typeClass();

See updated jsFiddle: select Point as chart type: http://jsfiddle.net/wergeld/nS4Ny/1/. This will throw that error.

like image 393
wergeld Avatar asked May 18 '12 18:05

wergeld


1 Answers

This issue is the capitalization of our drop-down values. Changed the check to do:

newType = newType.toLowerCase();

Now chart type changes great take effect. Full code:

function changeType(chart, series, newType) {
        newType = newType.toLowerCase();
        for (var i = 0; i < series.length; i++) {
            series = series[0];
            try {
                series.chart.addSeries({
                    type: newType,
                    stack: series.stack,
                    yaxis: series.yaxis,
                    name: series.name,
                    color: series.color,
                    data: series.options.data
                },
                false);
                series.remove();
            } catch (e) {
                alert(newType & ': ' & e);
            }
        }
    }
like image 114
wergeld Avatar answered Sep 25 '22 08:09

wergeld