• <i id='sRrYZ'><tr id='sRrYZ'><dt id='sRrYZ'><q id='sRrYZ'><span id='sRrYZ'><b id='sRrYZ'><form id='sRrYZ'><ins id='sRrYZ'></ins><ul id='sRrYZ'></ul><sub id='sRrYZ'></sub></form><legend id='sRrYZ'></legend><bdo id='sRrYZ'><pre id='sRrYZ'><center id='sRrYZ'></center></pre></bdo></b><th id='sRrYZ'></th></span></q></dt></tr></i><div id='sRrYZ'><tfoot id='sRrYZ'></tfoot><dl id='sRrYZ'><fieldset id='sRrYZ'></fieldset></dl></div>

    <tfoot id='sRrYZ'></tfoot>

      <small id='sRrYZ'></small><noframes id='sRrYZ'>

      1. <legend id='sRrYZ'><style id='sRrYZ'><dir id='sRrYZ'><q id='sRrYZ'></q></dir></style></legend>
          <bdo id='sRrYZ'></bdo><ul id='sRrYZ'></ul>
      2. 如何在charts.js 中旋转饼图?

        时间:2023-11-01

        <small id='hMzVy'></small><noframes id='hMzVy'>

      3. <legend id='hMzVy'><style id='hMzVy'><dir id='hMzVy'><q id='hMzVy'></q></dir></style></legend>

            • <bdo id='hMzVy'></bdo><ul id='hMzVy'></ul>
                <tbody id='hMzVy'></tbody>

                  <i id='hMzVy'><tr id='hMzVy'><dt id='hMzVy'><q id='hMzVy'><span id='hMzVy'><b id='hMzVy'><form id='hMzVy'><ins id='hMzVy'></ins><ul id='hMzVy'></ul><sub id='hMzVy'></sub></form><legend id='hMzVy'></legend><bdo id='hMzVy'><pre id='hMzVy'><center id='hMzVy'></center></pre></bdo></b><th id='hMzVy'></th></span></q></dt></tr></i><div id='hMzVy'><tfoot id='hMzVy'></tfoot><dl id='hMzVy'><fieldset id='hMzVy'></fieldset></dl></div>
                1. <tfoot id='hMzVy'></tfoot>
                  本文介绍了如何在charts.js 中旋转饼图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  看起来像 charts.js 中的饼图是通过在圆的上半部分取垂直半径,然后从那里顺时针移动来绘制的.这在大多数情况下都很好用,但是对于只有 2 个类别的饼图,如果可以旋转它以使切片居中,那就太好了,如下所示:

                  It looks like a pie in charts.js is drawn by taking a vertical radius on the top half of the circle, and then moving clockwise from there. This works great most of the time, but for a pie with only 2 categories, it would be nice if it could be rotated so that the slice is centered, like this:

                  旋转是通过取 360 的百分比并除以 2 来计算的.(.14*360)/2 = 25.2 度左,所以如果我可以申请的话

                  The rotation is calculated by taking the percentage of 360 and dividing by 2. (.14*360)/2 = 25.2 degrees left, so if I could just apply

                  transform: rotate(-25.2deg);
                  

                  到那个圈子我就好了.

                  由于 charts.js 将它放在画布上(而不是 <svg>),我不知道如何对其应用任何转换.不确定是否相关,但这是我的图表代码:

                  Since charts.js puts this on a canvas (as opposed to <svg>) I don't know how to apply any transformations to this. Not sure if relevant, but here is my code for the chart:

                  HTML

                  <canvas id=canvas style='width:300px;height:300px;'></canvas>
                  

                  JS

                  openRate = [
                              {
                                  value: 488,
                                  color: "#FF9030",
                                  highlight: "rgba(255, 144, 48, 0.44)",
                              },
                              {
                                  value: 3475,
                                  color: "#008DB7",
                                  highlight: "rgba(0, 141, 183, 0.82)"
                              }
                          ];
                  
                  var ctx=document.getElementById('canvas').getContext("2d");
                  var chart=new Chart(ctx).Pie(openRate);
                  

                  还有一个小提琴:http://jsfiddle.net/msy6kf3a/

                  推荐答案

                  你可以使用

                  chartjs中的轮换选项

                  我正在使用版本:2.1.6"

                  I'm using "Version: 2.1.6"

                  var options = {
                     rotation: (-0.5 * Math.PI) - (25/180 * Math.PI)
                  }
                  
                  var Chart = new Chart(ctx,{
                    type: 'pie',
                    data: data,
                    options: options
                  });
                  

                  更新了 fiddle

                  这篇关于如何在charts.js 中旋转饼图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:ChartJS 在 show() 调用时重放图表动画 下一篇:图表没有从它从 Jquery 收到的值更新

                  相关文章

                    <legend id='3SNDR'><style id='3SNDR'><dir id='3SNDR'><q id='3SNDR'></q></dir></style></legend>

                  1. <small id='3SNDR'></small><noframes id='3SNDR'>

                    <i id='3SNDR'><tr id='3SNDR'><dt id='3SNDR'><q id='3SNDR'><span id='3SNDR'><b id='3SNDR'><form id='3SNDR'><ins id='3SNDR'></ins><ul id='3SNDR'></ul><sub id='3SNDR'></sub></form><legend id='3SNDR'></legend><bdo id='3SNDR'><pre id='3SNDR'><center id='3SNDR'></center></pre></bdo></b><th id='3SNDR'></th></span></q></dt></tr></i><div id='3SNDR'><tfoot id='3SNDR'></tfoot><dl id='3SNDR'><fieldset id='3SNDR'></fieldset></dl></div>
                  2. <tfoot id='3SNDR'></tfoot>
                    • <bdo id='3SNDR'></bdo><ul id='3SNDR'></ul>