Chart node plotting issue

chart node is plotting only 12 points whereas there are var 30 points in the payload
The code is below,
'''series =["Average pressure","x"];
var labels = ["Labels"];
var data = ;

var i;

for (i = 0; i < msg.payload.length; i++) {
data.push({"x":msg.payload[i].date+"/"+ msg.payload[i].month +"/"+ msg.payload[i].year, "y":Number(msg.payload[i].pressure_avg)});

data = [data];

msg.payload = [{series, data, labels}];
return msg;'''

and how can i control my x-axis ?

If you are posting code please either surround it with ```

or use the </> above

It is just inside the function node, not the flow

It’s still code, it’s still easier to read if formatted correctly

corrected. is it ok ?

In the chart node what do you have defined for the X-axis?

I'm not sure that the x values are formatted correctly. It expects the x value to be in mS since 1970 (ie epoch time in milliseconds)

The values are from the payload. There I am getting date, month and year data separately so I am combining all to get x-axis in date/month/year format.

Yes. Which the chart can't understand. You need to convert to the correct format.

Can you please guide me ?

Use the JavaScript date function to parse your string. Google is your friend.

You mean Date.parse in dd-mm-yyyy fromat

Use google to search for converting date to javascript time stamp seconds

Where is your date coming from in the first place?

my date, month and year information is coming from the database which stores the same information from the RTC. btw the problem is solved as i parsed the date information in yyyy-mm-dd format.

1 Like