简体   繁体   English

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

[英]Set the Y-axis min value for kendo line chart dynamically

I wish to set the min value for my y-Axis to be 10 less than the lowest value in the Y-axis) .[Like if Min value is 83.33 (on Y-axis) so I want min value set to 73.33] 我希望将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)

Or at least .Min(MinValueOf Y-axis) 或至少.Min(Y轴的MinValue)

I was able to solve this.... 我能够解决这个问题。

$("#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
                });

Just to add to Suk's answer, if you're grouping your data, the view method returns an array of groups. 只是为了补充Suk的答案,如果您要对数据进行分组,则view方法将返回一组数组。 For each element in this array, access the items array to get the data for the current group. 对于此数组中的每个元素,访问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);
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM