动态设置剑道折线图的Y轴最小值

时间:2015-04-27 11:33:34

标签: javascript kendo-chart

我希望将y轴的最小值设置为10 less than the lowest value in the Y-axis)。[如果最小值为83.33(在Y轴上),那么我希望最小值设置为73.33]

.ValueAxis(axis => axis
.Numeric()
.Labels(labels => labels.Format("{0}"))
.AxisCrossingValue(-10)
.Line(line => line.Visible(false))
.Color("White").Min(MinValueOf Y-axis -10)

或者至少.Min(MinValueOf Y轴)

我能够解决这个问题....

$("#IndexChart").data("kendoChart").dataSource.read();

                //get reference to the chart widget
                var chart = $("#IndexChart").data("kendoChart");
                chart.bind("dataBound", function (e) {
                    var data = e.sender.dataSource.view(); 
                    //alert(JSON.stringify(data));

                    var allVals = [];//get all Y Axis data...
                    for (var i = 0; i < data.length; i++) {
                        allVals.push(data[i].DuplicatePrice);
                        allVals.push(data[i].OriginalPrice);
                    }

                    var least = Math.min.apply(Math, allVals); //get the least value
                    e.sender.options.valueAxis.min = least - 10; //set the least-10 as min
                });

1 个答案:

答案 0 :(得分:0)

只是要添加Suk的答案,如果要对数据进行分组,则view方法会返回一组数组。对于此数组中的每个元素,访问items数组以获取当前组的数据。

    // get filtered (and grouped) data
    var grpData = chart.dataSource.view();
    var allVals = [];

    // loop through all the groups in the view
    for (var grp = 0; grp < grpData.length; grp++) {
        // loop through data in each group
        for (var i = 0; i < grpData[grp].items.length; i++) {
            allVals.push(grpData[grp].items[i].DuplicatePrice);
            allVals.push(grpData[grp].items[i].OriginalPrice);
        }
    }