I am creating bar chart using chart.js which represents what medicine patient was taking and if it was working. X-axis is represented as timestamp.
In the image below you can see how it is supposed to look:
Green represents that medicine is working, red represents that it is not. As you can one medicine can be working for a while and then stop (see Metotrexat in the image).
Do you have any idea how this can be done using chart.js?
As of now, I have implemented it as separate records but I face these issues:
- How to put that label over all parts that belongs under one medicine when it has multiple records?
- How to achieve that border-radius as it can be multiple separate records which just act as one?
Thank you for your opinions.
We should've started from your attempts, the way you structured your data, etc. Because of that, this is only valid as an example, rather than a full solution.
One can set multiple colors of a bar using for the
backgroundColor
property, a LinearGradient color, described in the documentation.If we set the color stops a linear gradient like this:
the surface will be up to the 30% mark green and then abruptly change color for the rest of 70% to red.
Here's the code example. inspired by the image you pasted, with all the nitty-gritty implementation details