Create a bar chart, and having bar width propostional to the time elpased between to consecutive dates #518
Replies: 3 comments 5 replies
-
You can pass an array to width, which you can compute va $ex https://plotly.com/javascript/bar-charts/#customizing-individual-bar-widths |
Beta Was this translation helpful? Give feedback.
-
After some trials&errors, I think I succeeded with:
I don't know if a more elegant solution is possible, but it seems to do the job If it can help others :-) I noticed also something which is likely due to plotly itself I presume: |
Beta Was this translation helpful? Give feedback.
-
I use a number of variable width bars. bar width is in milliseconds. By default all bars are centred on the x value but to start the left side of the bar on the x value instead, use
some only have a start_time and end_time so calculate the duration:
Sometimes I reduce the width by 60000 and use offset: 30000. This makes a gap between the bars where that is desired. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,

I would like to enhance one of the graph I did to reach perfection :-)
So 99% of the time, I have a value every 30 mins, I know the start date, end date, value.
The initial difficulty was the sensor is encoding everything in its attributes which makes a simple thing to require help of a data scientist:
It's a reverse list of values in two attributes time and consumption
It took me some time to end-up with this working code:
So finding x and y is done, and as the frequency was supposed to always be 30mins, I used
width: $fn() => 1000*60*30
(so it works on left side)But it is incorrect for the general case: it should be the difference date[t+1] - date[t]
(otherwise i have gaps on the right side, as the utility provider was forced to give data aggregated per hour instead of 30mins)
Can anyone give me a hint to "compute" and "encode" this into the width attribute of plotly?
And as a challenge in the challenge, note that I used
filter: new Date(x).getHours() >= 6 && new Date(x).getHours() < 22
so that i can fill either blue or yellow my bars depending of the hour of the dayBeta Was this translation helpful? Give feedback.
All reactions