Responsive SVG line graph with Raphaël

时光总嘲笑我的痴心妄想 提交于 2019-12-13 17:03:13

问题


I'm looking at graphing solutions for my responsive webapp. I really like this Raphaël analytics demo: http://raphaeljs.com/analytics.html (Here it is on JS Bin: http://jsbin.com/svg/1/edit)

...but it's not responsive. I found this responsive SVG graph on codepen: http://codepen.io/meloncholy/pen/KxiJA, but I'm looking for a JavaScript integrated solution like Raphaël, not just a static SVG.

Any way to combine the two so as to make the Raphaël graph responsive?

Here's an article by the codepen demo's author on how he made the responsive SVG: http://meloncholy.com/blog/making-responsive-svg-graphs/


回答1:


The Raphaël Demo you posted renders the graph when the window.onload event is fired. The Demo generates with var r = Raphael("holder", width, height) a stage with a fixed width of 800px and draws the graph somewhere here r.drawGrid(...).

Similar to the codepen.io example you've posted, you could reinit/redraw the whole thing with a different width depending on the width of the window on the window.resize event.

A second approach, you loop through all SVG elements on the window.resize event with a similar var unscale = function (el) { ... } function like in codepen.io example.

Just some ideas...



来源:https://stackoverflow.com/questions/16848688/responsive-svg-line-graph-with-rapha%c3%abl

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