score:1

Accepted answer

i think your problem is that you are reusing the same options object each time you create the chart. try cloning the default options, then modify the cloned object to create the chart options. you can use jquery's extend method to do this. just make sure that you create new arrays for the categories and series each time, like so:

(function(){
    var chart,
    options = {
        chart: {
            renderto: 'linegr',
            defaultseriestype: 'line'
        },
        title: {
            text: 'malicious ips by type'
        },
        xaxis: {
            categories: []
        },
        yaxis: {
    title: {
           text: 'unique ips'
           }
        },
        subtitle: {
            text: 'last 10 days'
        },
        tooltip: {
            formatter: function() {
            return '<b>'+ this.x +'</b>: '+ roundval(this.y);
            }
        },
        plotoptions: {
            pie: {
                allowpointselect: true,
                cursor: 'pointer',
                datalabels: {
                    enabled: false
            },
            showinlegend: true
            }
        },
        series: [],
        exporting: {
            buttons: [
                {
                    symbol: 'diamond',
                    x: -62,
                    symbolfill: '#b5c9df',
                    hoversymbolfill: '#779abf',
                    _titlekey: 'reloadgraph',
                    onclick: function() {
                                        create();
                    }
                }
            ]
        }
    };

    function create() {
            if(chart) chart.destroy();
        $.get('dat.csv', function(data) {
            var newoptions = $.extend(true, {}, options, {
                xaxis : {
                    categories : []
                },
                series : []
            });

            // split the lines
            var lines = data.split('\n');

            // iterate over the lines and add categories or series
            $.each(lines, function(lineno, line) {
                var items = line.split(',');

                // header line containes categories
                if (lineno == 0) {
                    $.each(items, function(itemno, item) {
                        if (itemno > 0) newoptions.xaxis.categories.push(item);
                    });
                }

                // the rest of the lines contain data with their name in the first position
                else {
                    var series = {
                        data: []
                    };
                    $.each(items, function(itemno, item) {
                        if (itemno == 0) {
                            series.name = item;
                        } else {
                            series.data.push(parsefloat(item));
                        }
                    });

                    newoptions.series.push(series);

                }

            });

            // create the chart
            chart = new highcharts.chart(newoptions);

            $('#create').click(create);
            $('#destroy').click(chart.destroy);
        });
    }

    $(document).ready(create);
}());

Related Query

More Query from same tag