简体   繁体   English

如何在同一个 canvas 和 Apache ECharts 上切换图表?

[英]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个图表选项,每个选项显示一组不同的数据(在相同的时间跨度内)。

我目前拥有的图片;带有 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?这就是我现在所拥有的——它几乎是我想要的一切,除了下拉菜单在我看来让它看起来很乱,所以我想看看是否有人知道使用 Apache ECharts 的库函数很好地集成它的方法? 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 类似于:

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? tl; dr 是否有任何内置方法可以在 Apache ECharts 中的数据集之间切换?

I don't know your data, but this is my code.我不知道你的数据,但这是我的代码。
the same chart get different parameters,use filter function to deal.同一张图表得到不同的参数,使用过滤器function来处理。
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);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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