简体   繁体   中英

How to switch out charts on the same canvas with Apache ECharts?

Basically what I'm trying to do is have 5 options of graphs each displaying a different set of data (over the same span of time).

我目前拥有的图片;带有 5 个选项的下拉菜单

Here's what I have right now - it's almost everything I want, except the dropdown menu makes it look very messy in my opinion, so I wanted to see if anyone knew of a way using Apache ECharts' library functions to integrate it nicely? I've been looking through the docs for a few hours but I don't think anything fits.

If it helps, the function I'm using right now alongside the dropdown menu is something like:

function change_day_chart(value) {
    if (value == '0') {
        day_chart.setOption(prices, true);
    }
    if (value == '1') {
        day_chart.setOption(buy_volume, true);
    }
    if (value == '2') {
        day_chart.setOption(sell_volume, true);
    }
    if (value == '3') {
        day_chart.setOption(seven_day_buy, true);
    }
    if (value == '4') {
        day_chart.setOption(seven_day_sell, true);
    }
}

tl;dr is there any built-in way to switch between datasets in Apache ECharts?

I don't know your data, but this is my code.
the same chart get different parameters,use filter function to deal.
For your reference.Hope it can help you.

 var respon
$.ajax({
    url: 'api/url',
    type: 'post',
    contentType: 'application/json',
    dataType: 'json',
    success: function (rets) {
        respon = rets;
        $('#Select').trigger('change');
        //get all data
    },
    error: function (xhr, ajaxOptions, thrownError) {
        console.log(xhr.responseText);
    }
});

$('#Select').on('change', function () {
    var Qry = $(this).val(); //Select value
    var res = respon.filter(item => item.Flag == Qry)

    //do something
    var option = {
        //Omit
    };
    Chart.setOption(option,true);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM