Search code examples
zoomcharts

Zoomcharts with preloaded data


I am trying to use TimeChart with preloaded data, but I can't find a good example.

data = {'preloaded':{
    'unit':'s',
    'values':{'id':3,'name':'slice1','value':20}
}}

However I'm getting error: "Required field 'unit' not set in data"

Can you please recommend how specify the data properly?


Solution

  • This should work:

        var dataObj = {
            "dataLimitFrom":1279408157,
            "dataLimitTo":1384253671,
            "unit":"s",
            "values":[
              [1280062860,"8.221"],
              [1282209412,"4.2",],
              [1284577510,"5.9"],
              [1286988866,"1.52"],
            ]
        };
        var t = new TimeChart({
            container: document.getElementById("demo"),
            data:
            {
                units:["s"],
                timestampInSeconds: true,
                preloaded: dataObj
            }
        });
    

    For TimeChart in data array first one is always timestamp [1280062860,"8.221"].
    You can also change "unit" to any of ["s","m","h","d","M","y"]

    More about timechart: https://zoomcharts.com/developers/en/time-chart/api-reference/settings.html

    UPDATE: 'data' array containing timestamps and values is now called 'values'.