2

要件があります。つまり、ツリー ビューのチェック ボックスの選択に基づいて値軸を更新する必要があります。4 つの値軸を持つ 4 つのチェック ボックスを使用しています。見えない状態。

ここで、いくつかのコードを試して更新しました。

コード:

 <div id="treeview"></div>
  <div id="example" class="k-content">
            <div class="chart-wrapper">
                <div id="chart"></div>
            </div>
       </div> 

 var valueAxes = [
       { name: "KM",visible:false,
        title: { text: "KM" ,visible:false}
                                },
                              { name: "Miles Per Gallon",
                                    title: { text: "Miles Per Gallon" }
                                },

                            {
                                name: "Miles",

                                title: { text: "Miles " }
                            },

                            {
                                name: "liters per 100km", 
                                title: { text: "liters per 100km" }
                            }
                        ];
    function createChart() {
                        $("#chart").kendoChart({

                            legend: {
                                position: "top"
                            },
                            series: [{
                                type: "column",
                                data: [20, 40, 45, 30, 50],
                                stack: true,
                                name: "on battery",
                                color: "#003c72"
                            }, {
                                type: "column",
                                data: [20, 30, 35, 35, 40],
                                stack: true,
                                name: "on gas",
                                color: "#0399d4"
                            }, {
                                type: "area",
                                data: [30, 38, 40, 32, 42],
                                name: "mpg",
                                color: "#642381" 

                            }, {
                                type: "area",
                                data: [7.8, 6.2, 5.9, 7.4, 5.6],
                                name: "l/100 km",
                                color: "#e5388a" 

                            }],
                            valueAxes:valueAxes,                      
                            categoryAxis: {
                                categories: ["Mon", "Tue", "Wed", "Thu", "Fri"],

                                axisCrossingValues: [0, 0, 10, 10]
                            }

                        });
                    }

        $(document).ready(function() {    
            createChart();     
            $("#treeview").kendoTreeView({
              checkboxes: {
               checkChildren: true
                },
          dataSource: [{
            id: 1,
            text: "Value axis",
            expanded: true,
            items: [{
                id: 2,
                text: "KM"  
            },
            {
                id: 3,
                text: "Miles Per Gallon" 
            },
              {
                id: 4,
                text: "Miles "   
            },
              {
                id: 5,
                text: "liters per 100km"  
            }]
        }]
    }).data("kendoTreeView");
    $("#treeview").on("change", function (e) {
        var chart = $("#chart").data("kendoChart");
        var checkedSeries = [];    
        $("#treeview").find(":checked").each(function() {
          var nodeText =$(this).parent().parent().text();        
          $.each(valueAxes, function(index, valueAxes) {
             if (valueAxes.name == nodeText) {
              checkedSeries.push(valueAxes);
             checkedSeries.visible==="true";
             checkedSeries.title.visible===true;
                }
            });
        });    
        chart.options.valueAxes = checkedSeries;
        chart.refresh();
    });                     
    });

jsbin:値軸の変更

4

3 に答える 3

2

便宜上、最初にすべてのチャート軸をロードします。あなたが尋ねたようにその作業....

jsbin: http://jsbin.com/eyibar/37/edit

<html>
    <head>
        <link href="http://cdn.kendostatic.com/2013.1.319/styles/kendo.common.min.css" rel="stylesheet" type="text/css" />
        <link href="http://cdn.kendostatic.com/2013.1.319/styles/kendo.rtl.min.css" rel="stylesheet" type="text/css" />
        <link href="http://cdn.kendostatic.com/2013.1.319/styles/kendo.default.min.css" rel="stylesheet" type="text/css" />
        <link href="http://cdn.kendostatic.com/2013.1.319/styles/kendo.dataviz.min.css" rel="stylesheet" type="text/css" />
        <link href="http://cdn.kendostatic.com/2013.1.319/styles/kendo.dataviz.default.min.css" rel="stylesheet" type="text/css" />
        <link href="http://cdn.kendostatic.com/2013.1.319/styles/kendo.mobile.all.min.css" rel="stylesheet" type="text/css" />
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script src="http://cdn.kendostatic.com/2013.1.319/js/kendo.all.min.js"></script>
        <meta charset="utf-8" />
        <title>JS Bin</title>
        <style>
            #chart { width: 600px; }
        </style>
    </head>
    <body>
        <div id="treeview"></div>
        <div id="example" class="k-content">
            <div class="chart-wrapper">
                <div id="chart"></div>
            </div>
        </div>

        <script type="text/javascript">
            var valueAxes = [
                {
                    name: "KM",
                    title: { text: "KM" }
                },
                {
                    name: "Miles Per Gallon",
                    title: { text: "Miles Per Gallon" }
                },

               {
                   name: "Miles",
                   title: { text: "Miles " }
               },

               {
                   name: "liters per 100km",
                   title: { text: "liters per 100km" }
               }];

            function createChart(valueAxes) {
                $("#chart").kendoChart({

                    legend: {
                        position: "top"
                    },
                    series: [{
                        type: "column",
                        data: [20, 40, 45, 30, 50],
                        stack: true,
                        name: "on battery",
                        color: "#003c72"
                    }, {
                        type: "column",
                        data: [20, 30, 35, 35, 40],
                        stack: true,
                        name: "on gas",
                        color: "#0399d4"
                    }, {
                        type: "area",
                        data: [30, 38, 40, 32, 42],
                        name: "mpg",
                        color: "#642381"

                    }, {
                        type: "area",
                        data: [7.8, 6.2, 5.9, 7.4, 5.6],
                        name: "l/100 km",
                        color: "#e5388a"

                    }],
                    valueAxes: valueAxes,
                    categoryAxis: {
                        categories: ["Mon", "Tue", "Wed", "Thu", "Fri"],

                        axisCrossingValues: [0, 0, 10, 10]
                    }

                });
            }

            $(document).ready(function () {
                createChart(valueAxes);
                $("#treeview").kendoTreeView({
                    checkboxes: {
                        checkChildren: true
                    },
                    dataSource: [{
                        id: 1,
                        text: "Value axis",
                        expanded: true,
                        items: [{
                            id: 2,
                            text: "KM"
                        },
                        {
                            id: 3,
                            text: "Miles Per Gallon"
                        },
                          {
                              id: 4,
                              text: "Miles "
                          },
                          {
                              id: 5,
                              text: "liters per 100km"
                          }]
                    }]
                }).data("kendoTreeView");

                $("#treeview").on("change", function (e) {
                    var chart = $("#chart").data("kendoChart");
                    var checkedSeries = [];
                    if ($("#treeview").find(":checked").length != 0) {
                        $("#treeview").find(":checked").each(function () {
                            var nodeText = $(this).parent().parent().text();
                            $.each(valueAxes, function (index, valueAxes) {
                                if (valueAxes.name == nodeText.trim()) {
                                    checkedSeries.push(valueAxes);
                                    checkedSeries["visible"] = true;
                                }
                            });
                        });
                        createChart(checkedSeries);
                    }
                    else {
                        createChart(checkedSeries);
                    }
                });
            });

        </script>
    </body>
    </html>
于 2013-04-08T11:57:01.087 に答える
1

length==-1 の if 条件で creatChart(checkedAxes) 関数を呼び出すことで valueaxis をバインドおよびバインド解除できるようにコードを編集しました。その時点でシリーズは更新されません。

$("#treeview").on("change", function (e) {
              var chart = $("#chart").data("kendoChart");
              var checkedSeries = []; 
              var checkedAxes = [];
                if ($("#treeview").find(":checked").length !== -1){
                   $("#treeview").find(":checked").each(function () {
                   var nodeText = $(this).parent().parent().text();

                    $.each(valueAxes, function (index, valueAxes) {
                           if (valueAxes.name == nodeText) {
                               checkedAxes.push(valueAxes);
                               checkedAxes.visible = true;
                           }
                     });

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

                    chart.options.series = checkedSeries;
                    chart.options.valeAxes = checkedAxes;
                    chart.refresh();
                }
                    createChart(checkedAxes);
            });

しかし、creatChart(checkedAxes) 関数を呼び出さずに試してみると、チャートにバインドされたシリーズが更新されます。

$("#treeview").on("change", function (e) {
              var chart = $("#chart").data("kendoChart");
              var checkedSeries = []; 
              var checkedAxes = [];
                if ($("#treeview").find(":checked").length !== -1){
                   $("#treeview").find(":checked").each(function () {
                   var nodeText = $(this).parent().parent().text();

                    $.each(valueAxes, function (index, valueAxes) {
                           if (valueAxes.name == nodeText) {
                               checkedAxes.push(valueAxes);
                               checkedAxes.visible = true;
                           }
                     });

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

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

一度に両方のシナリオを取得できませんでした。申し訳ありませんが、解決策を見つけてください。

乾杯、ハッピーコーディング...

于 2013-04-09T07:33:13.573 に答える