<tfoot id='k3MOx'></tfoot>
      <legend id='k3MOx'><style id='k3MOx'><dir id='k3MOx'><q id='k3MOx'></q></dir></style></legend>
    1. <small id='k3MOx'></small><noframes id='k3MOx'>

        <bdo id='k3MOx'></bdo><ul id='k3MOx'></ul>

    2. <i id='k3MOx'><tr id='k3MOx'><dt id='k3MOx'><q id='k3MOx'><span id='k3MOx'><b id='k3MOx'><form id='k3MOx'><ins id='k3MOx'></ins><ul id='k3MOx'></ul><sub id='k3MOx'></sub></form><legend id='k3MOx'></legend><bdo id='k3MOx'><pre id='k3MOx'><center id='k3MOx'></center></pre></bdo></b><th id='k3MOx'></th></span></q></dt></tr></i><div id='k3MOx'><tfoot id='k3MOx'></tfoot><dl id='k3MOx'><fieldset id='k3MOx'></fieldset></dl></div>
    3. 如何使用 HTML5 和画布或 SVG 绘制网格

      时间:2023-06-20
      • <bdo id='9aAp2'></bdo><ul id='9aAp2'></ul>
        • <i id='9aAp2'><tr id='9aAp2'><dt id='9aAp2'><q id='9aAp2'><span id='9aAp2'><b id='9aAp2'><form id='9aAp2'><ins id='9aAp2'></ins><ul id='9aAp2'></ul><sub id='9aAp2'></sub></form><legend id='9aAp2'></legend><bdo id='9aAp2'><pre id='9aAp2'><center id='9aAp2'></center></pre></bdo></b><th id='9aAp2'></th></span></q></dt></tr></i><div id='9aAp2'><tfoot id='9aAp2'></tfoot><dl id='9aAp2'><fieldset id='9aAp2'></fieldset></dl></div>

          <small id='9aAp2'></small><noframes id='9aAp2'>

          <tfoot id='9aAp2'></tfoot>
            <tbody id='9aAp2'></tbody>

              <legend id='9aAp2'><style id='9aAp2'><dir id='9aAp2'><q id='9aAp2'></q></dir></style></legend>

                本文介绍了如何使用 HTML5 和画布或 SVG 绘制网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想画一个如图所示的网格,但我完全不知道从哪里开始.

                I want to draw a grid as shown in the image but I totally don't have any idea where to begin.

                我应该使用 SVG 还是应该使用带有 HTML5Canvas 以及如何在其上绘图?

                Should I use SVG or should I use Canvas with HTML5 and how do I draw on it?

                我希望此网格在其上绘制矩形、圆形或其他图表,我将计算该图表的面积,就像正方形的面积一样.

                I want this grid to draw rectangle, circle or other diagrams on it and I will calculate the area of that diagram like area of a square.

                推荐答案

                SVG 可以很好地使用模式:

                SVG can do this nicely using patterns:

                <svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">
                  <defs>
                    <pattern id="smallGrid" width="8" height="8" patternUnits="userSpaceOnUse">
                      <path d="M 8 0 L 0 0 0 8" fill="none" stroke="gray" stroke-width="0.5"/>
                    </pattern>
                    <pattern id="grid" width="80" height="80" patternUnits="userSpaceOnUse">
                      <rect width="80" height="80" fill="url(#smallGrid)"/>
                      <path d="M 80 0 L 0 0 0 80" fill="none" stroke="gray" stroke-width="1"/>
                    </pattern>
                  </defs>
                      
                  <rect width="100%" height="100%" fill="url(#grid)" />
                </svg>

                我将 widthheight 设置为 100%,因此您可以定义使用时的实际宽度和高度,无论是对于内联 SVG:

                I set width and height to 100%, so you can define the actual width and height on use, either for inline SVG:

                <div style="width:400px;height:300px">
                  <svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">
                    <defs>
                      <pattern id="smallGrid" width="8" height="8" patternUnits="userSpaceOnUse">
                        <path d="M 8 0 L 0 0 0 8" fill="none" stroke="gray" stroke-width="0.5"/>
                      </pattern>
                      <pattern id="grid" width="80" height="80" patternUnits="userSpaceOnUse">
                        <rect width="80" height="80" fill="url(#smallGrid)"/>
                        <path d="M 80 0 L 0 0 0 80" fill="none" stroke="gray" stroke-width="1"/>
                      </pattern>
                    </defs>
                        
                    <rect width="100%" height="100%" fill="url(#grid)" />
                  </svg>
                </div>

                或一个 <img> 元素:

                <img src="https://svgshare.com/i/9Eo.svg" width="700" height="200"/>
                

                结果:

                <img src="https://svgshare.com/i/9Eo.svg" width="241" height="401"/>
                

                结果

                请注意,对于这个特定的网格,如果您想要网格,您必须使用 nx 80 + 1 形式的宽度和高度(n 是任何整数)以粗笔画开始和结束.

                Note that for this particular grid you have to use widths and heights of the form n x 80 + 1 (with n being any integer) if you want the grid to start and end with a thick stroke.

                这篇关于如何使用 HTML5 和画布或 SVG 绘制网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:html5 canvas toDataURL 返回空白图片 下一篇:使用 jspdf 创建的 Pdf 文件太大

                相关文章

                1. <legend id='3HNWD'><style id='3HNWD'><dir id='3HNWD'><q id='3HNWD'></q></dir></style></legend>
                  <i id='3HNWD'><tr id='3HNWD'><dt id='3HNWD'><q id='3HNWD'><span id='3HNWD'><b id='3HNWD'><form id='3HNWD'><ins id='3HNWD'></ins><ul id='3HNWD'></ul><sub id='3HNWD'></sub></form><legend id='3HNWD'></legend><bdo id='3HNWD'><pre id='3HNWD'><center id='3HNWD'></center></pre></bdo></b><th id='3HNWD'></th></span></q></dt></tr></i><div id='3HNWD'><tfoot id='3HNWD'></tfoot><dl id='3HNWD'><fieldset id='3HNWD'></fieldset></dl></div>
                  1. <small id='3HNWD'></small><noframes id='3HNWD'>

                  2. <tfoot id='3HNWD'></tfoot>
                    • <bdo id='3HNWD'></bdo><ul id='3HNWD'></ul>