与图表更新用树形复选框选择工作不正常(Treeview checkbox selection wit

2019-10-17 19:51发布

在项目中,我的图表和TreeView,而页面加载图表更新不能正常工作意味着在这里仅树状两个复选框在页面加载检查,但是图表显示了所有领域values.i需要只显示选中复选框以图表的字段值,而页面加载, (页面加载后,它的正常工作)。

这里是小提琴: http://jsfiddle.net/RHh67/64/

我的图表代码:

$("#myChart").kendoChart({
    theme: $(document).data("kendoSkin") || "default",
    dataSource: {
        data: tmpData2,
        sort: {
            field: "date",
            dir: "asc"
        },
        schema: {
            model: {
                fields: {
                    date: {
                        type: "date"
                    }
                }
            }
        }
    },
    title: {
        text: "My Date-aware Chart"
    },
    legend: {
        position: "bottom"
    },
    seriesDefaults: {
        type: "line",
        labels: {
            visible: true
        },
        missingValues: "gap"
    },
    series: series,
    valueAxis: [{
        name: "A",
        labels: {
            format: "{0}%"
        }
    },
    {
        name: "B",
        labels: {
            format: "{0}D"
        }
    }],
    categoryAxis: {
        type: "Date",
        field: "date",
        axisCrossingValue: [0, 1000]
    }

});

Answer 1:

定义一个redrawChart即刷新,新系列的图表:

function redrawChart() {
    var chart = $("#myChart").data("kendoChart");

    var checkedSeries = [];

    $("#treeview").find(":checked").each(function () {
        var nodeText = $(this).parent().parent().text();

        $.each(series, function (index, series) {
            if (series.field == nodeText) {
                checkedSeries.push(series);
            }
        });
    });

    chart.options.series = checkedSeries;
    chart.refresh();
}

此功能需要调用:

  1. 在你的树的变化。
  2. 设置初始可见系列之后。

此外,移动至初始系列的选择以JavaScript代码的末尾。 我的意思是,第一初始化treeviewchart ,然后才初始化的初始值。

tree.dataItem(".k-item:nth(2)").set("checked", true);
tree.dataItem(".k-item:nth(3)").set("checked", true);
updateChks();
redrawChart();

完整的运行版本是在这里http://jsfiddle.net/OnaBai/RHh67/68/



文章来源: Treeview checkbox selection with graph updation is not working properly