Although F2 is based on Html5 Canvas, but for the current runtime environment, as long as it provides the same context interface as HTML5 Canvas does, F2 can still be able to run correctly.
The following table shows the functions that can be used under different runtime environment:
HTML5
Node
Chart Drawing
✔︎
✔︎
Legend
✔︎
✔︎
Tooltip
✔︎
Event (Tooltip, Legend interaction)
✔︎
Animation
✔︎
Rendering in Node
Running F2 on the node can provides a powerful server-side ability to render visualization charts. In this way, F2 can be used to generate offline reports, pdf and other visualization charts.
F2 currently supports all chart drawing functions in node runtime environment, but it does not provides events, interactions and animation capabilities (Please remove the code associated with chart.tooltip() and chart.animate() when try with the demos). Now let us start!
What needs to be explained here is that node does not support animation, events and Tooltip. Therefore, please try to avoid using above modules when using F2. This can also make a better package size. For convenience, it is recommended to require as follows:
Followings are two ways to create a chart, and note that width and height properties must be set in both ways.
// First way to create a chart, pass canvas directlyconstchart=newF2.Chart({ el: canvas,// pass the canvas object created in step 3 width:400,// must be set, width of the chart, same as the canvas height:267// must be set, height of the chart, same as the canvas});// Second way to create a chart, pass the canvas contextconstchart=newF2.Chart({ context:canvas.getContext('2d'),// pass the canvas context created in step 3 width:400,// must be set, width of the chart, same as the canvas height:267// must be set, height of the chart, same as the canvas});
Following is a complete example for drawing a pie chart:
The solution for resolution is simple: Assume that the pixel ratio of the current device is 2, then just set the pixelRation property when creating an F2 chart.
Here we set the width and height of the canvas to 375 * 360. After setting the pixelRatio to 2, the width and height of the canvas will be magnified by 2 times accordingly, therefore the chart's size will be 750*520. This way, you can ensure the clear display of the chart, as shown below: