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

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

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

      1. 如何使用 Chart.js 在标签中放置新行?

        How do I place a new line in a label with Chart.js?(如何使用 Chart.js 在标签中放置新行?)

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

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

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

                    <tbody id='t2mlu'></tbody>
                  <tfoot id='t2mlu'></tfoot>
                • 本文介绍了如何使用 Chart.js 在标签中放置新行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个使用 Chart.js 的带有标签的数据集.我想用换行符将标签分成两行.

                  I have a dataset with labels using Chart.js. I want to separate the label into two lines with a new line character.

                  <br/> 我都试过了,都不行.

                  I have tried <br /> and , and neither work.

                  labels: ['(A)<br />Waking', '(B)', '(C)', '(D)'],
                  labels: ['(A)
                  Waking', '(B)', '(C)', '(D)'], 
                  

                  第一个标签应该输出...

                  The first label should output like...

                  (A)
                  醒来

                  但它最终看起来像......

                  but it ends up looking like...

                  (A)<br/>醒来

                  (A) 醒来

                  推荐答案

                  查看文档,我可以看到多行标签是可能的.

                  Looking at the docs, I can see that multiline labels are possible.

                  更新的文档链接:https://www.chartjs.org/docs/latest/general/data-structures.html

                  我查看了一个示例的源代码,对于多行标签,它们将每个多行放在一个数组中,其中数组的每个元素都呈现在自己的行中.

                  I looked at the source code of an example and for multiline labels, they have each multiline in an array where each element of the array is rendered in its own line.

                  例如:

                  标签:[['(A)', 'Waking'], '(B)', '(C)', '(D)'],

                  请看下面的演示:

                  var randomScalingFactor = function() {
                    return Math.round(Math.random() * 100);
                  };
                  
                  window.chartColors = {
                      red: 'rgb(255, 99, 132)',
                      orange: 'rgb(255, 159, 64)',
                      yellow: 'rgb(255, 205, 86)',
                      green: 'rgb(75, 192, 192)',
                      blue: 'rgb(54, 162, 235)',
                      purple: 'rgb(153, 102, 255)',
                      grey: 'rgb(201, 203, 207)'
                  };
                  
                  var config = {
                    type: 'line',
                    data: {
                      labels: [
                        ['(A)', 'Walking'], '(B)', '(C)', '(D)'],
                      datasets: [{
                        label: 'My First dataset',
                        fill: false,
                        backgroundColor: window.chartColors.red,
                        borderColor: window.chartColors.red,
                        data: [
                          randomScalingFactor(),
                          randomScalingFactor(),
                          randomScalingFactor(),
                          randomScalingFactor()        
                        ]
                      }, {
                        label: 'My Second dataset',
                        fill: false,
                        backgroundColor: window.chartColors.blue,
                        borderColor: window.chartColors.blue,
                        data: [
                          randomScalingFactor(),
                          randomScalingFactor(),
                          randomScalingFactor(),
                          randomScalingFactor()
                        ],
                      }]
                    },
                    options: {
                      responsive: true,
                      title: {
                        display: true,
                        text: 'Chart with Multiline Labels'
                      },
                    }
                  };
                  
                  window.onload = function() {
                    var ctx = document.getElementById('canvas').getContext('2d');
                    window.myLine = new Chart(ctx, config);
                  };

                  <script src="https://www.chartjs.org/dist/2.8.0/Chart.min.js"></script>
                  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
                  <script src="https://ajax.cloudflare.com/cdn-cgi/scripts/a2bd7673/cloudflare-static/rocket-loader.min.js" data-cf-settings="100752039a7e60f6a2c8f47d-|49"></script>
                  
                  <div style="width:90%;">
                    <canvas id="canvas"></canvas>
                  </div>

                  这篇关于如何使用 Chart.js 在标签中放置新行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ChartJS Version 3 - common legend for multiple line charts(ChartJS 版本 3 - 多个折线图的常用图例)
                  Charts.js scales yaxes ticks min max doesnt work(Charts.js 缩放 yaxes 刻度 min max 不起作用)
                  How to expand the slice of donut chart in chartjs?(如何在chartjs中扩展圆环图的切片?)
                  Chart.js yAxes Ticks stepSize not working (fiddle)(Chart.js yAxes Ticks stepSize 不起作用(小提琴))
                  Rounded corners on chartJS v.2 - bar charts (with negative values)(chartJS v.2 上的圆角 - 条形图(带负值))
                  How to hide value in Chart JS bar(如何在 Chart JS 栏中隐藏值)

                    <bdo id='fwBzo'></bdo><ul id='fwBzo'></ul>
                      <tbody id='fwBzo'></tbody>

                        • <tfoot id='fwBzo'></tfoot>
                        • <small id='fwBzo'></small><noframes id='fwBzo'>

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

                          1. <legend id='fwBzo'><style id='fwBzo'><dir id='fwBzo'><q id='fwBzo'></q></dir></style></legend>