Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use canvas to draw coordinate Diagram in WeChat Mini Programs's Development

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "WeChat Mini Programs development how to use canvas to draw coordinate maps", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "WeChat Mini Programs development how to use canvas to draw coordinate maps" this article.

1. Line graph

Function draw (data, ctx) {var width, height = 300,ratioX, ratioY, maxY, stepY; var newArr = new Array (); / /-data processing-if (data.time = = null) {return;} if (data.type = = 'day' | | data.type = =' month') {var timeList = new Array (); for (var I = 0; I < data.time.length) If ((I% 4 = = 0 & & data.type = = 'day') | | (I% 5 = = 0 & & data.type = =' month')) {timeList.push (data.time.substr (data.timeI] .length-5,5));}} data.time = timeList;} else {for (var I = 0; I < data.time.length) Data.time +) {success [I] = data.time.substr (data.time.length-5,5);} / / the data returned by the background is displayed on the page / /-get the screen width-wx.getSystemInfo ({success: function (res) {width = res.windowWidth). }}) ratioX = parseInt ((width-60) / (data.time.length-1)); ratioY = parseInt ((height-45) / 6); / / find the maximum value of value for (var I = 0; I < data.list.length; ifold +) {newArr.push (Math.max.apply (Math, data.list [I] .value));} maxY = Math.max.apply (Math, newArr); stepY = Math.ceil (maxY / 4) / /-draw coordinate lines-ctx.beginPath (); for (var I = 0; I < 5; iTunes +) {ctx.save (); ctx.setStrokeStyle ("# dde2e3"); ctx.setFillStyle ("# 848198"); ctx.setFontSize ('8'); ctx.fillText (I * stepY, 0220-I * ratioY); ctx.moveTo (22,215-I * ratioY) Ctx.lineTo ((width-30), 215-I * ratioY); ctx.stroke (); ctx.restore ();} /-draw a legend-for (var I = 0; I < data.list.length; I +) {ctx.save (); ctx.translate (15215); ctx.beginPath (); ctx.setStrokeStyle (color [I]) Ctx.setLineCap ("round"); ctx.setLineWidth (10); ctx.moveTo (22 + I * 38,46); ctx.lineTo (38 + I * 38,46); ctx.stroke (); ctx.setFontSize ('8'); ctx.setFillStyle ("# 000000"); ctx.fillText (data.list.title, 21 + I * 38,66); ctx.restore () } / /-draw Abscissa-for (var I = 0; I < data.time.length; I +) {ctx.save (); ctx.translate (15215); ctx.setFontSize ('8'); ctx.setFillStyle ('# 848198'); ctx.fillText (data.time [I], I * (ratioX), 20); ctx.restore () } /-draw broken lines-for (var I = 0; I < data.list.length; iTunes +) {ctx.beginPath (); ctx.save (); ctx.translate (22,215); ctx.setStrokeStyle (color [I]); ctx.moveTo (0,-data.list [I] .value [0] / (stepY / ratioY)); / / console.log (data.list.value) For (var j = 0; j < data.list [I] .value.length; jacks +) {ctx.lineTo (j * (parseFloat ((width-53) / (data.list [I] .value.length-1)),-(data.list.value [j] / (stepY / ratioY); ctx.stroke ();} ctx.restore ();} ctx.draw ();}

2. Pie chart

Function draw (data, ctx) {var start = 0Power0, end,width; var ratio = new Array (); wx.getSystemInfo ({success: function (res) {width = res.windowWidth;}}); x = width / 2-15; for (var item0)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report