簡體   English   中英

Kendo折線圖-baseUnit適合-工具提示顯示錯誤的值

[英]Kendo Line chart - baseUnit fit - tooltip displaying the wrong value

當baseUnit設置為“ fit”時,我使用劍道折線圖遇到以下問題。 這里的問題是圖表渲染和數據之間不匹配。 請打開以下示例: http : //jsbin.com/geyeqi/edit?output

選擇2013年6月下的第二點,我希望使用以下值:4650。但是,工具提示顯示了錯誤的值(4850)。

有誰知道如何修理它? 我已經在telerik中打開了一張票: http : //www.telerik.com/forums/kendo-line-chart---baseunit-fit---tooltip-displaying-the-wrong-value

這是代碼:

window.minimumDate = new Date(Date.parse('03/01/2013'));
window.maximumDate = new Date(Date.parse('03/01/2015'));

$(document).ready(function () {
    var createLineChart = function (minDate, maxDate) {

        $("#plan-line-chart").kendoChart({
            dataSource: {
                data: getPrices(minDate, maxDate)
            },
            dataBound: function () {
                if (this.dataSource.view().length <= 12) {
                    this.options.categoryAxis.baseUnit = "months";
                }
            },
            legend: {
                position: "top"
            },
            seriesDefaults: {
                type: "line",
                style: "smooth"
            },
            seriesColors: ["rgba(178, 44, 27, 1)"],
            series:
            [
                 {
                     field: "CurrentPrice",
                     name: "Contributions",
                     categoryField: "Date"
                 }
            ],
            valueAxis: {
                majorGridLines: {
                    visible: true
                },
                line: {
                    visible: false
                },
                labels: {
                    template: "#= formatAmount(value) #"
                },
            },
            categoryAxis: {
                field: "Date",
                type: "Date",
                baseUnit: "fit",
                labels: {
                    rotation: 45
                },
                majorGridLines: {
                    visible: false
                }
            },
            tooltip: {
                visible: true,
                format: "{0}%",
                template: "#= formatAmount(value) #"
            }
        });
    };
    var rangeSliderOnChange = function (element) {
        var minDate = new Date(element.value[0]);
        var maxDate = new Date(element.value[1]);
        var linechart = $("#plan-line-chart").data("kendoChart");
        if (linechart != undefined) {
            linechart.destroy();
            createLineChart(minDate, maxDate);
        }
    };

    var templateString = "#= formatToMonthYear(selectionStart) # - #= formatToMonthYear(selectionEnd) #";

    $("#plan-range-slider").kendoRangeSlider({
        change: rangeSliderOnChange,
        min: window.minimumDate.getTime(),
        max: window.maximumDate.getTime(),
        smallStep: 86400000,
        largeStep: 86400000,
        tickPlacement: "none",
        tooltip: {
            template: kendo.template(templateString)
        }
    });

    createLineChart(window.minimumDate, window.maximumDate);
});

function formatAmount(amount) {
    return kendo.toString(amount, "#,##0.00");
}
function formatToMonthYear(val) {
    return kendo.toString(new Date(val), 'MMM yyyy');
}

function getPrices(min, max) {
    var prices = [
       {
           "Date": new Date(Date.parse('03/01/2015')),
           "CurrentPrice": 8250.00
       },
       {
           "Date": new Date(Date.parse('02/01/2015')),
           "CurrentPrice": 8000.00
       },
       {
           "Date": new Date(Date.parse('01/01/2015')),
           "CurrentPrice": 7750.00
       },
       {
           "Date": new Date(Date.parse('12/01/2014')),
           "CurrentPrice": 7500.00
       },
       {
           "Date": new Date(Date.parse('11/01/2014')),
           "CurrentPrice": 7250.00
       },
       {
           "Date": new Date(Date.parse('10/01/2014')),
           "CurrentPrice": 7000.00
       },
       {
           "Date": new Date(Date.parse('09/01/2014')),
           "CurrentPrice": 6750.00
       },
       {
           "Date": new Date(Date.parse('08/01/2014')),
           "CurrentPrice": 6550.00
       },
       {
           "Date": new Date(Date.parse('07/01/2014')),
           "CurrentPrice": 6350.00
       },
       {
           "Date": new Date(Date.parse('06/01/2014')),
           "CurrentPrice": 6150.00
       },
       {
           "Date": new Date(Date.parse('05/01/2014')),
           "CurrentPrice": 5950.00
       },
       {
           "Date": new Date(Date.parse('04/01/2014')),
           "CurrentPrice": 5750.00
       },
       {
           "Date": new Date(Date.parse('03/01/2014')),
           "CurrentPrice": 5550.00
       },
       {
           "Date": new Date(Date.parse('02/01/2014')),
           "CurrentPrice": 5450.00
       },
       {
           "Date": new Date(Date.parse('01/01/2014')),
           "CurrentPrice": 5350.00
       },
       {
           "Date": new Date(Date.parse('12/01/2013')),
           "CurrentPrice": 5250.00
       },
       {
           "Date": new Date(Date.parse('11/01/2013')),
           "CurrentPrice": 5150.00
       },
       {
           "Date": new Date(Date.parse('10/01/2013')),
           "CurrentPrice": 4950.00
       },
       {
           "Date": new Date(Date.parse('09/01/2013')),
           "CurrentPrice": 4950.00
       },
       {
           "Date": new Date(Date.parse('08/01/2013')),
           "CurrentPrice": 4850.00
       },
       {
           "Date": new Date(Date.parse('07/01/2013')),
           "CurrentPrice": 4750.00
       },
       {
           "Date": new Date(Date.parse('06/01/2013')),
           "CurrentPrice": 4650.00
       },
       {
           "Date": new Date(Date.parse('05/01/2013')),
           "CurrentPrice": 4550.00
       },
       {
           "Date": new Date(Date.parse('04/01/2013')),
           "CurrentPrice": 4450.00
       },
       {
           "Date": new Date(Date.parse('03/01/2013')),
           "CurrentPrice": 4350.00
       }
    ];

    var currentPrices = [];
    $("#currentPrices").text('');
    var minDate = new Date((min.getMonth() + 1) + '/01/' + min.getFullYear());
    var maxDate = new Date((max.getMonth() + 1) + '/01/' + max.getFullYear());
    for (var i = prices.length - 1; i >=  0; i--) {
        if (prices[i].Date >= minDate && prices[i].Date <= maxDate) {
            currentPrices.push(prices[i]);

            $("#currentPrices").append("<li>" + kendo.toString(prices[i].Date, 'MMM yyyy') + " :: " + prices[i].CurrentPrice + "</li>");
        }
    }
    return currentPrices;
}

多虧了Telerik,我找到了解決它的方法。 請閱讀他們的回復

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM