• <legend id='YgSuk'><style id='YgSuk'><dir id='YgSuk'><q id='YgSuk'></q></dir></style></legend>

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

        Chartjs - pointColor 跟随渐变描边的当前颜色

        Chartjs - pointColor to follow current color of gradient stroke(Chartjs - pointColor 跟随渐变描边的当前颜色)
          • <tfoot id='SAj2y'></tfoot>

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

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

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

                  本文介绍了Chartjs - pointColor 跟随渐变描边的当前颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我刚刚使用

                  I just created Line Chart using chartjs library and I managed to make stroke in gradient color. Here is simple fiddle example what I did so far.

                  What I need next, is to make pointColor to follow gradient stroke and to pick up the current color of it's position. Like on this photo.

                  Any ideas how to achieve that?

                  Thanks!

                  解决方案

                  Update

                  From @AndyHolmes question at Is it possible to add a drop shadow to chart.js line chart?

                  The original solution (extending) is not required. All that is required is simply

                    ...
                    pointColor: gradientstroke
                    ...
                  


                  Original Solution

                  Just extend the line and update the point colors. You could do it in the draw function, but it would be efficient (when you have animation enabled) to do it in initialize function

                  Chart.types.Line.extend({
                      name: "LineAlt",
                      initialize: function (data) {
                          Chart.types.Line.prototype.initialize.apply(this, arguments);
                  
                          var ctx = this.chart.ctx;
                          // draw a line with the gradient, we use this to get each points color
                          ctx.fillStyle = data.datasets[0].strokeColor;
                          ctx.fillRect(0, 0, this.chart.width, 1);
                  
                          this.datasets.forEach(function (dataset) {
                              dataset.points.forEach(function (point) {
                                  // get the color from the gradient drew above
                                  var imageData = ctx.getImageData(point.x, 0, 1, 1);
                                  var color = 'rgba(' + imageData.data[0] + ', ' + imageData.data[1] + ', ' + imageData.data[2] + ', ' + imageData.data[3] + ')';
                  
                                  // the _saved is used by the tooltip refresh to draw the point when you mouseout
                                  point.fillColor = color;
                                  point._saved.fillColor = color;
                                  point.strokeColor = color;
                                  point._saved.strokeColor = color;
                              })
                          })
                  
                          // we need to call the render function again to overwrite what was drawn in the initialize render (otherwise we don't see the changed color when animation is false)
                          // this also wipes out the reference gradient
                          this.render();
                      }
                  });
                  

                  The pointColor and pointStrokeColor in the lineChartData are actually not required. Note that you could also override the pointHighlightStroke and pointHighlightFill the same way if you wanted to.

                  You call it like so

                  new Chart(ctx).LineAlt(...
                  


                  Fiddle - http://jsfiddle.net/w2nh153d/


                  这篇关于Chartjs - pointColor 跟随渐变描边的当前颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  在开发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 在一年的第一天返回前一年)

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

                2. <legend id='B8YCo'><style id='B8YCo'><dir id='B8YCo'><q id='B8YCo'></q></dir></style></legend>
                      <bdo id='B8YCo'></bdo><ul id='B8YCo'></ul>

                        <tbody id='B8YCo'></tbody>

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