1

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).

Image of what I currently have; dropdown menu with the 5 options

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?

csjh
  • 154
  • 2
  • 11

1 Answers1

0

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.

 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);
});
Dharman
  • 30,962
  • 25
  • 85
  • 135
蔡驛洋
  • 166
  • 1
  • 7