从比较图表中删除图表系列

时间:2014-07-16 17:10:27

标签: javascript highcharts highstock

尝试从比较图表中删除其中一个图表包含5个图表系列。

有五个复选框,每个复选框都在检查中添加图表...如果复选框取消选中,则取消选中图表。我试过chart.series [2],但是如果按钮1,2和3检查图表显示所有三个,如果取消选中第二个复选框,而不是图表2没有关闭而是显示所有三个和相同的其他3,4和5 。

$('li').click(function (evt) { if ($(this).attr("class") == "BtnA" || $(this).attr("class") == "BtnB" || $(this).attr("class") == "BtnC" || $(this).attr("class") == "BtnD" || $(this).attr("class") == "BtnE") {
            $(this).addClass("selected");
            if ($(this).addClass("selected")) {

                switch ($(this).attr("class")) {
                    case "BtnA selected": testing_name = "test1"; names = 'testname1';
                        break;
                    case "BtnB selected": testing_name = "test2"; names = 'testname2';
                        break;
                    case "BtnC selected": testing_name = "test3"; names = 'testname3';
                        break;
                    case "BtnD selected": testing_name = "test4"; names = 'testname4';
                        break;
                    case "BtnE selected": testing_name = "test5"; names = 'testname5';
                        break;
                }
                chart(testing_name, names);
            }else if ($(this).attr("class") == "BtnA selected" || $(this).attr("class") == "BtnB selected" || $(this).attr("class") == "BtnC selected" || $(this).attr("class") == "BtnD selected" || $(this).attr("class") == "BtnD selected") {
            $(this).removeClass("selected");
                            $('li').each(function () {

                             $('#container').charts('tested').series[2].hide();
                            }

和函数调用chart();

               function chart(testing_name, names) {

        $(function () {

            var seriesOptions = [],
        yAxisOptions = [],
        seriesCounter = 0;

            if (data == 0) {
                series_names = ["data"];
                jsonfilename = ["datajson"];
            }

            data++;
            series_names.push(names);

            jsonfilename.push(testing_name);


            $.each(series_names, function (i, name) {

                $.getJSON(jsonfilename[i] + ".txt", function (data) {
                    seriesOptions[i] = {
                        name: name,
                        data: data
                    };
                    seriesCounter++;

                    if (seriesCounter == series_names.length) {
                        createChart();
                    }
                });
            });



            // create the chart when all data is loaded
            function createChart() {

                $('#container').highcharts('StockChart', {

                    rangeSelector: {
                        inputEnabled: $('#container').width() > 480,
                        selected: 4
                    },

                    yAxis: {
                        labels: {
                            formatter: function () {
                                return (this.value > 0 ? '+' : '') + this.value + '%';
                            }
                        },
                        plotLines: [{
                            value: 0,
                            width: 2,
                            color: 'silver'
                        }]
                    },

                    plotOptions: {
                        series: {
                            compare: 'percent'
                        }
                    },

                    tooltip: {
                        pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
                        valueDecimals: 2
                    },

                    series: seriesOptions
                });
            }


        });

    }

您能为此提供任何参考代码吗?

谢谢&amp;问候, ShailShin

0 个答案:

没有答案