<tfoot id='WAqam'></tfoot>

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

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

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

        Chart.js - 在条形图中绘制水平线(类型栏)

        Chart.js - draw horizontal line in Bar Chart (type bar)(Chart.js - 在条形图中绘制水平线(类型栏))
          <bdo id='jmH3T'></bdo><ul id='jmH3T'></ul>
          <i id='jmH3T'><tr id='jmH3T'><dt id='jmH3T'><q id='jmH3T'><span id='jmH3T'><b id='jmH3T'><form id='jmH3T'><ins id='jmH3T'></ins><ul id='jmH3T'></ul><sub id='jmH3T'></sub></form><legend id='jmH3T'></legend><bdo id='jmH3T'><pre id='jmH3T'><center id='jmH3T'></center></pre></bdo></b><th id='jmH3T'></th></span></q></dt></tr></i><div id='jmH3T'><tfoot id='jmH3T'></tfoot><dl id='jmH3T'><fieldset id='jmH3T'></fieldset></dl></div>
            • <small id='jmH3T'></small><noframes id='jmH3T'>

                <tbody id='jmH3T'></tbody>
            • <tfoot id='jmH3T'></tfoot>

                <legend id='jmH3T'><style id='jmH3T'><dir id='jmH3T'><q id='jmH3T'></q></dir></style></legend>

                  本文介绍了Chart.js - 在条形图中绘制水平线(类型栏)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Good evening , I want to draw a horizontal line on a graph Bar Chart using Chart.js .

                  I read the question Chart.js - draw horizontal line and I could not draw the line on a Bar Chart, as indicated is the implementation for Line Chart.

                  My code is implemented to jsfiddle

                  HTML

                  <div>
                    <canvas id="ctx"></canvas>
                  </div>
                  

                  JS

                  var data = {
                      labels: ["Docente 1", "Docente 2", "Docente 3", "Docente 4", "Docente 5", "Docente 6", "Docente 7"],
                      datasets: [
                          {
                              label: "Semestre 2017-I",
                              borderWidth: 1,
                              data: [3.65, 2.59, 1.80, 2.81, 0.56, 0.55, 3.40]
                          }
                      ]
                  };            
                  
                  var ctx = document.getElementById("ctx");
                  
                  var myBarChart = new Chart(ctx, {
                     type: 'bar',
                     data: data
                  });
                  

                  and it would be able to draw the horizontal line, obtaining a graph of the form: http://i.stack.imgur.com/QlOKG.png

                  解决方案

                  HTML:

                  <div>
                    <canvas id="ctx" width="600" height="400"></canvas>
                  </div>
                  

                  JS:

                  var data = {
                                  labels: ["Docente 1", "Docente 2", "Docente 3", "Docente 4", "Docente 5", "Docente 6", "Docente 7"],
                                  datasets: [
                                      {
                                          label: "Semestre 2017-I",
                                          borderWidth: 1,
                                          data: [3.65, 2.59, 1.80, 2.81, 0.56, 0.55, 3.40]
                                      }
                                  ]
                              };            
                  
                  var ctx = document.getElementById("ctx").getContext("2d");
                  
                  Chart.types.Bar.extend({
                      name: "BarWithLine",
                      initialize: function () {
                          Chart.types.Bar.prototype.initialize.apply(this, arguments);
                      },
                      draw: function () {
                          Chart.types.Bar.prototype.draw.apply(this, arguments);
                  
                          var lineHeight = 2; // <----
                  
                          // draw line
                          this.chart.ctx.beginPath();
                          this.chart.ctx.moveTo(0, this.scale.calculateY(lineHeight));
                          this.chart.ctx.strokeStyle = '#ff0000';
                          this.chart.ctx.lineTo(this.chart.width, this.scale.calculateY(lineHeight));
                          this.chart.ctx.stroke();
                      }
                  });
                  
                  var myBarChart = new Chart(ctx).BarWithLine(data, {
                    type: 'bar',
                    data: data
                  });
                  

                  Here is the fiddle: http://jsfiddle.net/zk9oc4c9/

                  Important: I changed the Chart.js library URL to: http://www.chartjs.org/assets/Chart.min.js

                  And removed https from the fiddle.

                  这篇关于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 栏中隐藏值)

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

                  1. <tfoot id='wACLg'></tfoot>

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

                      • <bdo id='wACLg'></bdo><ul id='wACLg'></ul>

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