问题
Using ChartJs (v2.2.2) can you change the line style between the last 2 points on a graph. e.g. have a solid line all the way and then dashed at the end? see picture below
回答1:
The borderDashproperty (scroll to Line Configuration) is the key to your problem.
The thing is, the full chart is drawn with a border dash, you cannot choose where it starts and where it ends.
A simple workaround is to create two identical datasets. One dotted and one with a plain line. Then you remvoe the last data of your plain one, and they both will be displayed as how you want it.
You can see the full code in this jsFiddle, and here is its result :
Note :
- Since there are two datasets now, the legend will display both of them. Setting the
display
to false fixes it (more or less). - The declaration order doesn't matter since the plain line will always overwrite the dotted one.
- Having a bezier curve (
tension
property > 0) can create a display problem since the data is not the same in both datasets.
来源:https://stackoverflow.com/questions/39399264/in-chartjs-is-it-possible-to-change-the-line-style-between-different-points