Javascript 选择要显示的数据使用ajax显示您的值,并使用chart.series[0]更新图表。更新方法。抱歉,我的错误未更新fiddle,请立即尝试此处:,也更新了回答抱歉,但我的问题是如何使此图表随着输入数据的更改而更改,而不是如何更改图表类型。无论如何,Thx

Javascript 选择要显示的数据使用ajax显示您的值,并使用chart.series[0]更新图表。更新方法。抱歉,我的错误未更新fiddle,请立即尝试此处:,也更新了回答抱歉,但我的问题是如何使此图表随着输入数据的更改而更改,而不是如何更改图表类型。无论如何,Thx,javascript,php,jquery,ajax,datepicker,Javascript,Php,Jquery,Ajax,Datepicker,选择要显示的数据使用ajax显示您的值,并使用chart.series[0]更新图表。更新方法。抱歉,我的错误未更新fiddle,请立即尝试此处:,也更新了回答抱歉,但我的问题是如何使此图表随着输入数据的更改而更改,而不是如何更改图表类型。无论如何,Thx for tryingfiddle也会更新数据,数据:[7.0,6.9,9.5,14.5,18.2,16.0]从代码中删除类型:“列”,。它只会更新你的数据哦,是的,我意识到了。但是如果我在图表中有多个图形,该怎么做呢?在chart.serie


选择要显示的数据使用ajax显示您的值,并使用
chart.series[0]更新图表。更新
方法。抱歉,我的错误未更新fiddle,请立即尝试此处:,也更新了回答抱歉,但我的问题是如何使此图表随着输入数据的更改而更改,而不是如何更改图表类型。无论如何,Thx for tryingfiddle也会更新数据,数据:[7.0,6.9,9.5,14.5,18.2,16.0]从代码中删除
类型:“列”,
。它只会更新你的数据哦,是的,我意识到了。但是如果我在图表中有多个图形,该怎么做呢?在
chart.series[0].update
中,
chart
是变量的名称(请参阅jsfiddle
chart=new Highcharts.chart({})
),因此对于其他图表,请使用不同的变量(即chart2)并使用新变量更新图表(chart2.series[0].update)我知道这是一篇老文章,但是如何在generate_graph文件中输出数据呢?谢谢
$(document).ready(function() {
        var a;
        options = {
        chart   : {renderTo: 'chart', type: 'line', marginRight: 130, marginBottom: 25},
        credits : {enabled: false},
        title   : {text: 'Sales Performance', x: -20},
        xAxis   : {categories: [{}]},
        yAxis   : {title: {text: '(IDR - millions)'}, plotLines: [{value: 0,width: 1,color: '#808080'}]},
        legend  : {layout: 'vertical', align: 'right', verticalAlign: 'top', x: -10, y: 100, borderWidth: 0},
        tooltip : {
            valueDecimals: 2,
            formatter: function() {
                var s = '<b>'+ this.x +'</b>';
                $.each(this.points, function(i, point) {
                    s += '<br/>'+point.series.name+': '+point.y;
                });
                return s;
            },
            shared: true
        },
        <?php echo $series; ?> // resulted like this -> series: [{},{},{}.{}];
    };
    $.ajax({
        url : "generate_graph",
        type    : 'post',
        dataType: "json",
        success : function(data){ //to get data from multiple sales
            options.xAxis.categories = data.categories;
            for(a = 0; a < data.count; a++){
                options.series[a].name = data.name[a];
                options.series[a].data = data.value[a];
            }
            var chart = new Highcharts.Chart(options);          
        }
    });
})
chart.series[0].update({
                   data: [7.0, 6.9, 9.5, 14.5, 18.2, 16.0]
});
$(document).ready(function() {
    var a;
    options = {
        chart   : {renderTo: 'chart', type: 'line', marginRight: 130, marginBottom: 25},
        credits : {enabled: false},
        title   : {x: -20},
        xAxis   : {categories: [{}]},
        rangeSelector: {inputDateFormat: '%y-%m-%e'},
        yAxis   : {title: {text: '(IDR - millions)'}, plotLines: [{value: 0,width: 1,color: '#808080'}]},
        legend  : {layout: 'vertical', align: 'right', verticalAlign: 'top', x: -10, y: 100, borderWidth: 0},
        tooltip : {
            valueDecimals: 2,
            formatter: function() {
                var s = '<b>'+ this.x +'</b>';
                $.each(this.points, function(i, point) {
                    s += '<br/>'+point.series.name+': '+point.y;
                });
                return s;
            },
            shared: true
        },
        <?php if($ty == '1' || $ty == '2')
        { 
            echo $series;
        } 
        else { ?>
            series: [{}]
        <?php } ?>
    };

    //initial
    $.ajax({
        url     : "generate_graph",
        type    : 'post',
        dataType: "json",
        success : function(data){
            options.xAxis.categories    = data.categories;
            options.title.text          = data.title;
            for(a = 0; a < data.count; a++){
                options.series[a].name = data.name[a];
                options.series[a].data = data.value[a];
            }
            var chart = new Highcharts.Chart(options);          
        }
    });
})

$(function() {
    var dates = $('#from, #to').datepicker({
        onSelect: function(selectedDate) {
            var option = this.id =='from'?'minDate':'maxDate',
            instance = $(this).data('datepicker'),
            date = $.datepicker.parseDate(
                instance.settings.dateFormat || $.datepicker._defaults.dateFormat,
                selectedDate,
                instance.settings
            );
            dates.not( this ).datepicker('option',option,date);

            // validate if we have both dates and get new series from server
            if ($(dates[0]).datepicker('getDate') && $(dates[1]).datepicker('getDate')) {
                var from = $(dates[0]).datepicker("getDate");
                var to =   $(dates[1]).datepicker("getDate");
                $.ajax({
                    url: 'generate_graph',
                    data: {
                        'from'  : from.getFullYear() + "-" + ("0" + (from.getMonth()+1)).slice(-2) + "-" + ("0" + from.getDate()).slice(-2), 
                        'to'    : to.getFullYear() + "-" + ("0" + (to.getMonth()+1)).slice(-2) + "-" + ("0" + to.getDate()).slice(-2),
                        'data'  : $('select[name="data"]').val()
                        },
                    type: 'post',
                    dataType: 'json',
                    success: function(data){
                        options.xAxis.categories    = data.categories;
                        options.title.text          = data.title;
                        for(a = 0; a < data.count; a++){
                            options.series[a].name = data.name[a];
                            options.series[a].data = data.value[a];
                        }
                        var chart = new Highcharts.Chart(options);  
                    }
                });
            }
        }
    });
});
<div>
                <label for="from">Select Data</label>
                <select name="data">
                    <option value="Sales Revenue">Sales Revenue</option>
                    <option value="Actual Profit">Actual Profit</option>
                </select>
                <label for="from">From</label>
                <input type="text" id="from" name="from" size="15"/>
                <label for="to">to</label>
                <input type="text" id="to" name="to" size="15"/>
            </div>
            <div id="chart"></div>