2

我每个函数都有问题,我想在不同的div中加载一个具有相同名称的highcharts,并使用ajax函数重新加载。

我正在阅读以这种方式加载图表的旧帖子:

$('.portlet_content_18').each(function(){
var chart = new Highcharts.Chart({
    chart: {
        renderTo: this,
        height: 400
    },
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },

    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]        
    }]
});
}));

对我有用的东西,但当我更改为 ajax 调用时就不行了。

我的代码使用 ajax 调用,只加载名为“graphcontainer”的第一个 div 是下一个:

function graph() {
    $(function () {

        $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function (data) {
            // Create the chart
            window.chart = new Highcharts.StockChart({
                chart: {
                    renderTo: 'graphcontainer'
                },
                rangeSelector: {
                    selected: 1
                },

                title: {
                    text: 'AAPL Stock Price'
                },

                series: [{
                    name: 'AAPL',
                    data: data,
                    tooltip: {
                        valueDecimals: 2
                    }
                }]
            });
        });
    });
}

我尝试添加每个函数,以便它加载到其他 div 中而没有结果。希望您能够帮助我。

4

1 回答 1

2

根据 HighChart API和 HighStock API

renderTo: String|Object
The HTML element where the chart will be rendered. 
If it is a string, the element by that id is used. 
The HTML element can also be passed by direct reference. Defaults to null.

首先,Highchart 需要传递"id"div 元素。因此,我怀疑传递类名如何与您提到的第一个示例一起使用。

你能分享你从哪里得到前HighChart一个例子吗?

其次,你有一个包含id="graphcontainer"和包含Highstock的div

<script src="http://code.highcharts.com/stock/highstock.js"></script>
于 2013-01-03T17:30:24.830 回答