In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article Xiaobian for you to introduce in detail "how to draw the tree structure in html5 graphics", the content is detailed, the steps are clear, the details are handled properly, I hope that this "how to draw tree structure graphics in html5" article can help you solve doubts, following the editor's ideas slowly in-depth, together to learn new knowledge.
The code is as follows:
Const canvas_options= {canvasWidth: 750,750570, chartZone: [70Magne70750570], / / coordinate drawing area yAxisLabel: ['0% canvasHeight: 10%, 20%, 30%, 40%, 50%, 60%, 70%, 80%, 80%, 90%, 100%], / y-axis coordinate text yAxisLabelWidth: 70% of the maximum width of the y-axis of the pencil. / / maximum value of y-axis middleLine: 410, / / midline pillarWidth: 10 middleLine / column width distanceBetween: 50 Gap between the two sides of the drawing area pillar: [120,070700750], / / histogram drawing area mainTrunkHeight: 90Grampact / bottom starting trunk height dialogWidth: 300gambit / pop-up window width dialogLineHeight: 30pm / pop-up window height dialogDrawLineMax: 4,} const nodeClick = [] Var chooseNode = null Const datalist= {showDataInfo: {city: [{name: 'item 1 node, status: 1, / / status: 0 completed 1 in progress node: [{value: 10, date:' 2020-03-12 15 50 name 50 name 52, content: 'for organizing information and operations It is also usually used as an entrance to detailed information.' }, {value: 20, date: '2020-03-12 15 content 50 content:' is used to organize information and operations, usually as an entrance to detailed information.' },]}, {name: 'project 2, status: 0, / / status: 0 completed 1 in progress node: [{value: 10, date:' 2020-03-12 15 node 50 50 node 02, content: 'for organizing information and operations It is also usually used as an entrance to detailed information.' }, {value: 50, date: '2020-03-12 15 content 50 content:' is used to organize information and operations, usually as an entrance to detailed information.' }, {value: 100,100,100, date: '2020-03-12 15 content 50 content:' is used to organize information and operations, usually as an entrance to detailed information.' },]}, {name: 'project 3 minutes, status: 1, / / status: 0 completed 1 in progress node: [{value: 20, date:' 2020-03-12 15 node 50 node 02colors, content: 'for organizing information and operations It is also usually used as an entrance to detailed information.' }, {value: 30, date: '2020-03-12 15 content 50 content:' is used to organize information and operations, usually as an entrance to detailed information.' }, {value: 40, date: '2020-03-12 15 content 50 content:' is used to organize information and operations, usually as an entrance to detailed information.' },]}, {name: 'project 419, status: 1, / / status: 0 completed 1 in progress node: [{value: 20, date:' 2020-03-12 15 node 50 node 02, content: 'for organizing information and operations It is also usually used as an entrance to detailed information.' }, {value: 30, date: '2020-03-12 15 content 50 content:' is used to organize information and operations, usually as an entrance to detailed information.' },]},]} const canvas = document.getElementById ("canvas"); const ctx = canvas.getContext ('2d'); ctx.save (); drawYLabel (canvas_options,ctx); / / draw y-axis coordinates drawStartButton (ctx,canvas_options); drawData (ctx,datalist.showDataInfo,canvas_options) Canvas.addEventListener ("click", event= > {/ / clear the previous pop-up window if) {ctx.clearRect (0,0, canvas.width, canvas.height); ctx.save (); drawYLabel (canvas_options,ctx); / / draw y-axis coordinates drawStartButton (ctx,canvas_options); drawData (ctx,datalist.showDataInfo,canvas_options) ChooseNode = null} / / decide to click on the node let rect = canvas.getBoundingClientRect (); let zoom = rect.width/canvas_options.canvasWidth; let x = (event.clientX/zoom-rect.left/zoom) .tofixed (2); let y = (event.clientY/zoom-rect.top/zoom) .tofixed (2); for (var twee0mitt {let indexVal = number==1?1:index) Let numberVal = number==1?2:number-1 let x0 = options.chartZone [0] + options.distanceBetween+ (options.chartZone [2]-options.chartZone [0]-options.distanceBetween*2) / numberVal*indexVal; let value = item.node.length-1] .value; let height = (value/options.yAxisLabelMax* (options.chartZone [3]-options.chartZone [0]) * 0.98) .tofixed (2); let y0=options.chartZone [3]-height / / ctx.beginPath () at the bottom of the bar chart; ctx.fillStyle='# eee'; ctx.fillRect (x0-5 recorder 80) options.chartZone [3]-80); / / Bezier curve ctx.beginPath (); ctx.strokeStyle = item.status==0? "# d35453":'# 24b99aqu; ctx.lineWidth=options.pillarWidth; ctx.moveTo (options.middleLine,options.pillar [3]) / / the starting point of the Bezier curve ctx.lineTo (options.middleLine,options.canvasHeight-50-options.mainTrunkHeight); / / the middle vertical bar ctx.quadraticCurveTo of the Bezier curve. (x0recoveryoptions.canvasHeightLecotion. MainTrunkHeightZone [3]); / / the progress of drawing the bar chart ctx.lineTo (x0Corely0); ctx.stroke () / / draw text ctx.font= "28px'"; ctx.textAlign='center'; ctx.fillStyle= "# 333"; ctx.fillText (item.name,x0,options.chartZone [1]-20) / / draw the node item.node.forEach ((node_item,node_index) = > {let y1 = options.chartZone [3]-(node_item.value/options.yAxisLabelMax* (options.chartZone [3]-options.chartZone [0]) * 0.98) .tofixed (2); ctx.beginPath (); ctx.arc (x0memt y1ml15) 0Math.PIQU2Magne.true) Ctx.fillStyle= "rgba"; ctx.fill (); ctx.beginPath (); ctx.arc (x0Person2); ctx.fillStyle= "rgba"; ctx.fill () Const pointInfo= {x:x0, y:y1, date: node_item.data, content: node_item.content, value: node_item.value}; nodeClick.push (pointInfo) })})} read here, this article "how to draw the graph of tree structure in html5" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it before you can understand it. If you want to know more about related articles, welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.