0

该代码有效,但我想动态更改图表类型。我尝试在函数 WeightLine 中更改图表类型但是它不起作用。它改变了 SeriesDefault 类型,我在警报中看到了新的图表类型,但没有绘制新的图表类型。

 var mydata=[{"date":"2013-03-06","data":2916,"name":"weight"},{"date":"2013-03-05","data":3708,"name":"weight"}];
            function getFilter(xMin, xMax) {      
    return [{
        field: "date",
        operator: "gt",
        value: xMin
        }, {
        field: "date",
        operator: "lt",
        value: xMax
    }];
}
          $("#line_chart_weight").kendoChart({
                    title: {
                        text: "weight"
                    },
                    dataSource:{
    data: mydata,
    group: {
                    field: "name"
                },

                sort: {
                    field: "date",
                    dir: "asc"
                },

                schema: {
                    model: {
                        fields: {
                            date: {
                                type: "date"
                            }
                        }
                    }
                }
},
                    seriesDefaults: {
                        type: "scatterLine"
                    },
                    series: [{
                        xField:"date",
                        yField: "data"


                    }],
                    yAxis: {
                        labels: {
                            format: "{0}"


                        },
                            title: {
  text: "KG",
  padding: {
    left: 20
  }}
                    }, xAxis: {
                      labels:
                  {
                  rotation: -90,
                    format:"dd-MM-yyyy"
                  },
                    title: {
  text: "Date",
  padding: {
    top: 20
  }},
  type:"date",
  name:"CategoryAxis"
                    },   

                      tooltip: {
    visible: true,
    format:"dd-MM-yyyy",
    color:"white"
},
 transitions: false,
drag: onDragw,
    zoom: onDragw
                });

                var weight=$("#line_chart_weight").data("kendoChart");
                function onDragw(e) {

        var ds = weight.dataSource;
        var options = weight.options;
            e.originalEvent.preventDefault();
        var categoryRange = e.axisRanges.CategoryAxis; 
        if (categoryRange) {
            var xMin = categoryRange.min;
            var xMax = categoryRange.max;    
            options.categoryAxis.min = xMin;
            options.categoryAxis.max = xMax;      
            ds.filter(getFilter(xMin, xMax));
            weight.redraw();    
        }

    }
 function WeightLine(WeightTypeString){ weight.options.seriesDefaults.type=WeightTypeString;alert(weight.options.seriesDefaults.type); weight.redraw();}                    
4

1 回答 1

0

这有点奇怪,但我写了一些东西来解决这个问题。他们都为我工作。您可以为您的代码修改它们。

1.

var chart = $("#chartId").data("kendoChart");
chart.setOptions({ seriesDefaults: {type : "radarColumn"} });
chart.dataSource.read();
chart.refresh();

2.

var chart = $("#chartId").data("kendoChart");
for(i = 0; i< chart.options.series.length;i++){
     chart.options.series[i].type = "radarColumn";
}
chart.refresh();
于 2014-05-22T07:33:42.503 回答