Using highcharts & highstock together on same page

空扰寡人 提交于 2019-12-24 22:00:14

问题


Hope someone can help.. ? I'm trying to use both highcharts and highstock on a single page, loading from CDN, initially I set up various highcharts - gauge and bar chart with drilldown and using the following all is working fine:

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/drilldown.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/solid-gauge.js"></script>

I now have a highstock chart but I can't get it to work together on the same page - I've tried just using highstock (without highcharts) and then adding highcharts-more and the modules, also tried using highcharts and then loading highstock as a module which didn't work either e.g

<script src="https://code.highcharts.com/modules/highstock.js"></script> OR

<script src="https://code.highcharts.com/modules/stock.js"></script>

I assume the order of the CDN links is crucial to make it work too?

I'm also aware that when rendering the charts highcharts uses Highcharts.chart and highstock uses Highcharts.stockChart - so how would this work when using both?

Many thanks.


回答1:


By using Highstock, you can create both stockChart and standard chart with additional modules:

Highcharts.chart('container', {
    series: [{
        type: 'solidgauge',
        data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
    }]
});

Highcharts.stockChart('container1', {
    series: [{
        type: 'line',
        data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
    }]
});

Live demo: http://jsfiddle.net/BlackLabel/54ezsbgr/

If you really need to use Highstock and Highcharts separately, you can do it in this way:

<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script>
    var Highstock = Highcharts;
    Highcharts = null;
</script>
<script src="https://code.highcharts.com/highcharts.js"></script>

Live demo: http://jsfiddle.net/BlackLabel/0vshoqpa/



来源:https://stackoverflow.com/questions/52517950/using-highcharts-highstock-together-on-same-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!