d3.js visualization on android 2.3

前端 未结 2 1137
抹茶落季
抹茶落季 2021-02-10 01:44

I know that the android browser for 2.3 does not support SVG, but I\'d like to know whether I could convert a d3.js SVG Visualization to a canvas using Canvg on clientside. Is t

2条回答
  •  再見小時候
    2021-02-10 02:30

    Actually you CAN use Canvg to display d3's SVG as canvas on the client side. Following the code in here: http://jsfiddle.net/plaliberte/HAXyd/ you just feed the div with the generated SVG to the Canvg function. The only catch is that if you use ".style" in part of your d3 operations it will throw an error for some reason. For example:

    .style("text-anchor","middle")
    

    In Android 2.x it throws:

    TypeError: Result of expression 'this.style' [null] is not an object
    

    Therefore you will need to modify these methods to use .attr("style" instead:

    .attr("style", "text-anchor:middle")
    

    There are also functions inside d3 that use the style method like axis, so you may also need to make this substitution inside the library.

提交回复
热议问题