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

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

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

        <tfoot id='BMZE6'></tfoot>

        角度图添加水平线

        时间:2023-11-02
        • <small id='Tpe2J'></small><noframes id='Tpe2J'>

              <legend id='Tpe2J'><style id='Tpe2J'><dir id='Tpe2J'><q id='Tpe2J'></q></dir></style></legend>
            • <i id='Tpe2J'><tr id='Tpe2J'><dt id='Tpe2J'><q id='Tpe2J'><span id='Tpe2J'><b id='Tpe2J'><form id='Tpe2J'><ins id='Tpe2J'></ins><ul id='Tpe2J'></ul><sub id='Tpe2J'></sub></form><legend id='Tpe2J'></legend><bdo id='Tpe2J'><pre id='Tpe2J'><center id='Tpe2J'></center></pre></bdo></b><th id='Tpe2J'></th></span></q></dt></tr></i><div id='Tpe2J'><tfoot id='Tpe2J'></tfoot><dl id='Tpe2J'><fieldset id='Tpe2J'></fieldset></dl></div>
                <tbody id='Tpe2J'></tbody>
                <bdo id='Tpe2J'></bdo><ul id='Tpe2J'></ul>
                <tfoot id='Tpe2J'></tfoot>
                  本文介绍了角度图添加水平线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在这里添加水平线 [Chart.js - 绘制水平线 到我的 angular-chart.js(如果我理解正确,我需要做的就是扩展线型图表).

                  I want add horizontal line like here [Chart.js - draw horizontal line to my angular-chart.js (if I understand right, what I need to do is to extend the line type chart).

                  我应该如何以及在哪里做(编写自己的指令,尝试在 angular .config 中扩展 char.js)?

                  How and where I should do it (write own directive, try extend the char.js in angular .config)?

                  推荐答案

                  首先,您需要使用您在帖子中提到的扩展来扩展 Chart.js,如下所示:(使用 @jbman223 片段)

                  First of all, you need to extends Chart.js with the extend you mentionned in your post, like this : (using @jbman223 snippet)

                  // Extend chart.js with a new type of chart
                  Chart.types.Line.extend({
                     name: "LineWithLine",
                     initialize: function () {
                        Chart.types.Line.prototype.initialize.apply(this, arguments);
                     },
                     draw: function () {
                      Chart.types.Line.prototype.draw.apply(this, arguments);
                  
                      // Needs to be set with angular-chart options
                      var lineAtIndex = 2;
                  
                      var point = this.datasets[0].points[lineAtIndex]
                      var scale = this.scale
                      console.log(this);
                  
                      // draw line
                      this.chart.ctx.beginPath();
                      this.chart.ctx.moveTo(scale.startPoint+12, point.y);
                      this.chart.ctx.strokeStyle = '#ff0000';
                      this.chart.ctx.lineTo(this.chart.width, point.y);
                      this.chart.ctx.stroke();
                  
                      // write TODAY
                      this.chart.ctx.textAlign = 'center';
                      this.chart.ctx.fillText("TODAY", scale.startPoint + 35, point.y+10);
                  }
                  });
                  

                  然后,我们必须将这个新的图表类型与角度图表联系起来.不幸的是,它是一个高级抽象库,因此没有内置功能.因此,到目前为止,我发现这样做的唯一方法是通过在配置中添加一行来修改 angular-chart.js:

                  Then, we have to link this new Chart type with angular-chart. Unfortunately, it is a high level of abstraction library, so there is no built-in feature for that. So, the only way I have found to do that so far is to modify angular-chart.js by adding a line in the config :

                    return angular.module('chart.js', [])
                    .provider('ChartJs', ChartJsProvider)
                    .factory('ChartJsFactory', ['ChartJs', '$timeout', ChartJsFactory])
                    //...
                    .directive('chartLinebis', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('LineWithLine'); }]);
                  

                  最后,用你的新图表标签调用 angular-chart :

                  Finally, call angular-chart with your new chart label :

                        <canvas class="chart chart-linebis" chart-data="data" chart-labels="labels" chart-legend="true" chart-series="series"></canvas>
                  

                  请注意,js 导入遵守此顺序非常重要:chart.js -> myExtend.js -> angular-chart.js

                  Note that it is very important that the js imports respect this order : chart.js -> myExtend.js -> angular-chart.js

                  JSFiddle (免责声明:我在片段中间包含了 angular-chart.js进口订单目的)

                  JSFiddle (disclaimer : I included angular-chart.js in the middle of the snippet for import order purpose)

                  这篇关于角度图添加水平线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Chart.js - 在折线图中为背景的特定部分着色 下一篇:ChartJS - 查找平底锅内的最小和最大标签(缩放时)

                  相关文章

                  1. <small id='pZJv2'></small><noframes id='pZJv2'>

                    1. <tfoot id='pZJv2'></tfoot>
                    2. <legend id='pZJv2'><style id='pZJv2'><dir id='pZJv2'><q id='pZJv2'></q></dir></style></legend>
                        <bdo id='pZJv2'></bdo><ul id='pZJv2'></ul>

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