dashed ticklines/gridlines in flot

2019-02-07 04:19发布

I am pretty new to this flot API. I want to have dashed gridlines/ticklines instead of solid line both X-axis' and Y-axis'. Can anyone help me with this??

Thanks in advance!

标签: jquery grid flot
2条回答
姐就是有狂的资本
2楼-- · 2019-02-07 04:36

I was able to produce dashed lines for the grid's markings by modifying the library. I'm currently using Flot ver 0.8.0

First I added a new attribute under grid (around line 400), just below the markingsLineWidth:

markingsStyle: 'dashed'

Since Flot is using canvas to render the charts, I added a dashedLineTo() extension for the canvas using this code from David Owens. I added it just right after the color parser plugin on top of the Flot's code, with credits given to David. The dashedLineTo() has the following parameters:

dashedLineTo(fromX, fromY, toX, toY, pattern)

For the pattern, I used [5,5] which means there will alternating 5px of dash, and 5px of space.

Finally I modified the drawGrid function in the plugin, when the markings are being drawn.

if(options.grid.markingsStyle == 'dashed') {
    ctx.dashedLineTo(xrange.from, yrange.from, xrange.to, yrange.to, [5,5])
} else {
    ctx.moveTo(xrange.from, yrange.from);
    ctx.lineTo(xrange.to, yrange.to);
}

Just thought you can use this as a reference when modifying the library.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-02-07 04:49

Unfortunately Flot doesn't currently provide a way to change grid/tick line styles. You would have to modify the library itself.

查看更多
登录 后发表回答