In ChartJS is it possible to change the line style between different points?

别等时光非礼了梦想. 提交于 2019-12-21 22:29:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!