Question

tl;dr: when I set the xAxis min and max to, say, 2013-01-01 14:30:00 and 2013-01-01 15:45, I need to see these times on the xAxis and not 14:00 and 15:00, or 01. 01. 2013 and 01. 01. 2013, or whatever automatically generated timestamps that are wrong, like here


I have a question here regarding the Kendo Dataviz Chart. I'm trying to display several scatter line graphs in one chart that depict how some technical indicators change in time. For that I need to display correct date and time to the scale of minuted. And I don't seem to be able to reach this seemingly simple goal, no matter how much I search or try.

Research done so far:
Answer from Telerik did little to help.

All examples and demos use day-granularity at maximum, so no help there.

Here is some example code, that I didn't manage to get advantage of: jsbin.com/AtusAGO/1/edit

The code:
Please try commenting and uncommenting lines 23 to 27 in the JSFiddle to see what happens (mostly nothing, really, and never what I'd like to achieve).

(function () {
    $("#chart").kendoChart({
        legend: {
            visible: true,
            position: "bottom"
        },
        seriesDefaults: {
            type: "scatterLine",
            markers: {
                size: 0
            }
        },
        xAxis: {
            "type": "date",
            labels: {
                format: "hh:mm d. M. yyyy"
            },
            title: {
                text: "Time"
            },
            min: "2012-02-05 00:35:00",
            max: "2012-02-05 01:40:00",
            baseUnitStep: "auto",
            /*baseUnit: "fit",
                            maxDateGroups: 10,*/
            autoBaseUnitSteps: {
                minutes: [5]
            }
        },
        series: [{
            "name": "temp",
                "yAxis": "temperature",
                "data": [
                [
                    "2012-02-05T00:35:00",
                3],
                [
                    "2012-02-05T00:55:00",
                0],
                [
                    "2012-02-05T01:00:00",
                1],
                [
                    "2012-02-05T01:05:00",
                2],
                [
                    "2012-02-05T01:10:00",
                3],
                [
                    "2012-02-05T01:15:00",
                4],
                [
                    "2012-02-05T01:20:00",
                5],
                [
                    "2012-02-05T01:40:00",
                3]
            ]
        }, {
            "name": "hum",
                "yAxis": "humidity",
                "data": [
                [
                    "2012-02-05T00:00:00",
                80],
                [
                    "2012-02-05T00:55:00",
                100],
                [
                    "2012-02-05T01:00:00",
                10],
                [
                    "2012-02-05T01:05:00",
                20],
                [
                    "2012-02-05T01:10:00",
                50],
                [
                    "2012-02-05T01:15:00",
                40],
                [
                    "2012-02-05T01:20:00",
                50],
                [
                    "2012-02-05T01:51:00",
                30]
            ]
        }],
        yAxes: [{
            "name": "humidity",
                "title": {
                "text": "Humidity [%]"
            }
        }, {
            "name": "temperature",
                "title": {
                "text": "Temperature [\u00b0C]"
            }
        }]
    });
}());
Was it helpful?

Solution

You can use the following data format:

series:{
data: [
    {
        date: new Date(2013,0,1,0,0,0),
        value: 23
    },
    {
        date: new Date(2013,0,2,0,0,0),
        value: 24
    }
],
field: "value",
categoryField: "date"
}

And in the labels, you can set it as

template: "#:kendo.toString(value,'dd/MM/yyyy hh:mm:ss')"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top