• <legend id='39ris'><style id='39ris'><dir id='39ris'><q id='39ris'></q></dir></style></legend>
      <bdo id='39ris'></bdo><ul id='39ris'></ul>

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

        <small id='39ris'></small><noframes id='39ris'>

        <tfoot id='39ris'></tfoot>

      1. Chart.js 2.X 中的条形值 - dataset.metadata 未定义

        Bar values in Chart.js 2.X - dataset.metadata undefined(Chart.js 2.X 中的条形值 - dataset.metadata 未定义)
      2. <legend id='0dJoZ'><style id='0dJoZ'><dir id='0dJoZ'><q id='0dJoZ'></q></dir></style></legend>

          <small id='0dJoZ'></small><noframes id='0dJoZ'>

          <tfoot id='0dJoZ'></tfoot>
              <tbody id='0dJoZ'></tbody>

                • <bdo id='0dJoZ'></bdo><ul id='0dJoZ'></ul>

                  <i id='0dJoZ'><tr id='0dJoZ'><dt id='0dJoZ'><q id='0dJoZ'><span id='0dJoZ'><b id='0dJoZ'><form id='0dJoZ'><ins id='0dJoZ'></ins><ul id='0dJoZ'></ul><sub id='0dJoZ'></sub></form><legend id='0dJoZ'></legend><bdo id='0dJoZ'><pre id='0dJoZ'><center id='0dJoZ'></center></pre></bdo></b><th id='0dJoZ'></th></span></q></dt></tr></i><div id='0dJoZ'><tfoot id='0dJoZ'></tfoot><dl id='0dJoZ'><fieldset id='0dJoZ'></fieldset></dl></div>
                  本文介绍了Chart.js 2.X 中的条形值 - dataset.metadata 未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 Chart.js 2 的新手,因此我们将不胜感激.

                  I am quite new at Chart.js 2, so any help will be appreciated.

                  我正在尝试显示图表中每个条形的值.正如 使用图表在帕累托图中显示值中的建议.js 2.0.2 和其他用户我正在使用这个解决方案.但是,这部分会抛出异常 TypeError: dataset.metaData is undefined:

                  I'm trying to show values for each bar in the chart. As suggested in Display values in Pareto chart using Chart.js 2.0.2 and other users I'm using this solution. However, this part throws an exception TypeError: dataset.metaData is undefined :

                  dataset.metaData.forEach(function(p) {
                     ctx.fillText(p._chart.config.data.datasets[p._datasetIndex].data[p._index], p._model.x, p._model.y  + 20);
                  });
                  

                  我只想在栏上显示值.有什么帮助吗?

                  I just want to show the value over the bar. Any help?

                  推荐答案

                  使用下面更新的 onComplete,您的代码应该可以使用 Chart.js v2.1

                  With the below updated onComplete, your code should work with Chart.js v2.1

                  ...
                  var options = {
                      animation: {
                          onComplete: function() {
                              var ctx = this.chart.ctx;
                              ctx.textAlign = "center";
                              ctx.textBaseline = "middle";
                              var chart = this;
                              var datasets = this.config.data.datasets;
                  
                              datasets.forEach(function (dataset, i) {
                                  ctx.font = "20px Arial";
                                  switch (dataset.type) {
                                      case "line":
                                          ctx.fillStyle = "Black";
                                          chart.getDatasetMeta(i).data.forEach(function (p, j) {
                                              ctx.fillText(datasets[i].data[j], p._model.x, p._model.y - 20);
                                          });
                                          break;
                                      case "bar":
                                          ctx.fillStyle = "White";
                                          chart.getDatasetMeta(i).data.forEach(function (p, j) {
                                              ctx.fillText(datasets[i].data[j], p._model.x, p._model.y + 20);
                                          });
                                          break;
                                  }
                              });
                          }
                      },
                      ...
                  

                  <小时>

                  小提琴 - http://jsfiddle.net/0j4g7kxy/

                  我假设您只需要 bar,但我在 onComplete 中保留了 line 的代码,所以它应该可以工作也适用于线路.如果您也不需要,只需从 onComplete 代码中删除相关的 case 代码

                  I've assumed you needed only the bar, but I have retained the code for line in the onComplete, so it should work for lines too. If you don't need either, just remove the related case from the onComplete code

                  这篇关于Chart.js 2.X 中的条形值 - dataset.metadata 未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                • <legend id='HfUTO'><style id='HfUTO'><dir id='HfUTO'><q id='HfUTO'></q></dir></style></legend>
                    <tbody id='HfUTO'></tbody>

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

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

                          <tfoot id='HfUTO'></tfoot>