Stacked bar charts #35
-
|   Hi @dbuezas Cheers, Hans  |  
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
|   hi @oischinger 👋  |  
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|   Try this instead then: type: custom:plotly-graph entities: - entity: sensor.teich_plug_wattage - entity: sensor.beamer_plug_wattage - entity: sensor.office_plug_wattage - entity: sensor.backofen_plug_wattage hours_to_show: 6 refresh_interval: 1 title: Power Consumption (24h) color_scheme: 2 layout: barmode: stack defaults: entity: stackgroup: one line: shape: spline lambda: |-  (ys, xs) => {  const MINUTES = 15; // <-- change here  const window_size_ms = 1000*60*MINUTES ;  const result = {x:[], y:[]};  const t0 = Math.ceil(+xs[0]/window_size_ms)*window_size_ms;  const t1 = Math.ceil(+xs[xs.length-1]/window_size_ms)*window_size_ms;  let i = 0;   let y_accum = 0;  let y_count = 0;  for (let t = t0; t <= t1; t+= window_size_ms){  while(xs[i] < t && i < xs.length){  const x = +xs[i];  const y = +ys[i];  if (!Number.isNaN(y)){  // ignore unavailable/unknown state points  y_accum += y;  y_count ++;  }   i++;  }  const avg = y_count==0? 0 :y_accum/y_count;  result.y.push(avg);  result.x.push(new Date(t));  y_accum = 0;  y_count = 0;  }  return result;  }In this approach, we're iterating over each interval and then searching for the datapoints that happen to fall within it. This ensures that intervals without datapoints will still be present in the result (with an average of zero) The only issue I see with this approach is that the first and last interval may be incomplete so it will show lower than real values. You can fix that by removing the first and last element of the x and y attributes before returning the result  |  
Beta Was this translation helpful? Give feedback.






Try this instead then: