如何使Chart JS中的两行变粗

Sti*_*hof 15 javascript chart.js

我用Chart JS制作了一个图表,你可以在我的小提琴中看到.此图表中有三行.我希望橙色和黄色线比现在更厚.绿色虚线很好.

我四处搜寻,尝试过一些东西.但我还没有找到合适的解决方案.我希望我的问题很明确,有人可以帮助我.

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.6/Chart.min.js" charset="utf-8"></script>
<canvas id="canvas2"></canvas>
Run Code Online (Sandbox Code Playgroud)

JavaScript的

Chart.defaults.global.legend.display = false;
var lineChartData = {
labels: ['20°', '30°', '40°', '50°', '60°', '70°', '80°'],
datasets: [{
  data: [null, null, null, 400, 320, 220, 90],
  pointBorderColor: "rgba(75,192,192,1)",
  pointBackgroundColor: "#fff",
  borderColor: '#FFEC8B',
  pointBorderWidth: 0,
  pointHoverRadius: 0,
  pointHoverBackgroundColor: "rgba(75,192,192,1)",
  pointHoverBorderColor: "rgba(220,220,220,1)",
  pointHoverBorderWidth: 0,
  lineWidth: 100,
  pointRadius: 0,
  pointHitRadius: 0,
},{
  data: [550, 520, 470, 400, null, null, null],
  borderColor: '#ff8800',
  pointBorderWidth: 0,
  pointHoverRadius: 0,
  pointHoverBackgroundColor: "rgba(75,192,192,1)",
  pointHoverBorderColor: "rgba(220,220,220,1)",
  pointHoverBorderWidth: 0,
  pointRadius: 0,
  pointHitRadius: 0,
},
{
    data: [220, 220, 220, 220, 220, 220, 220],
    borderColor: '#008080',
    borderDash: [10, 10],
    pointBorderWidth: 0,
    pointHoverRadius: 0,
    pointHoverBackgroundColor: "rgba(75,192,192,1)",
    pointHoverBorderColor: "rgba(220,220,220,1)",
    pointHoverBorderWidth: 0,
    pointRadius: 0,
    pointHitRadius: 0,
  }
]
};

var ctx = document.getElementById("canvas2").getContext("2d");
var myChart = new Chart(ctx, {
 type: "line",
 beginAtZero: true,
 scaleOverride:true,
 scaleSteps:9,
 scaleStartValue:0,
 lineWidth: 100,
 scaleStepWidth:100,
 data: lineChartData,
 options: {
    elements: {
        line: {
            fill: false
        }
    },
    style: {
      strokewidth: 10
    },
    scales: {
      xAxes: [{
        display: true,
        scaleLabel: {
          display: true,
          labelString: 'Temperatuur - Celcius'
        }
      }],
      yAxes: [{
        display: true,
        ticks: {
            max: 600,
            min: 0,
            stepSize: 200,
            userCallback: function(value, index, values) {
                value = value.toString();
                value = value.split(/(?=(?:...)*$)/);
                value = value.join('.');
                return value + '%';
              }
        },
        scaleLabel: {
          display: true,
          labelString: 'Rendement'
        }
      }]
    }
  }
})
Run Code Online (Sandbox Code Playgroud)

tek*_*tiv 32

你接近它了!
其实,你必须编辑属性不是lineWidth,但borderWidth(在第一个例子 chart.js之文档,你可以看到属性).


正如MDN doc 的示例中所述lineTo:

使用beginPath()开始绘制线条的路径,使用moveTo()移动笔,并使用stroke()方法实际绘制线条.

该线基本上是一个宽度为的矩形0.然后使用矩形边框宽度计算线条的宽度.


因此,您只需以这种方式编辑数据集:

datasets: [{
    // ...
    borderWidth: 1 // and not lineWidth
    // ...
}]
Run Code Online (Sandbox Code Playgroud)

我也更新了你的小提琴编辑,你可以看到它现在正在工作.