ChartJS / ChartJS-плагин-аннотация устанавливает высоту вертикальной линии - PullRequest
0 голосов
/ 04 марта 2019

Можно ли установить высоту вертикальной линии на графике js?enter image description here

Например, этот пример: https://jsfiddle.net/caj89x6L/

{
  type: 'line',
  id: 'vline' + index,
  mode: 'vertical',
  scaleID: 'x-axis-0',
  value: date,
  **endValue: 3.5, ?? 
  height: 3.5,** ?? 
  borderColor: 'green',
  borderWidth: 1,
  label: {
     enabled: true,
     position: "center",
     content: amount[index]
  }

}

Можно ли где-нибудь установить свойство высоты?endValue dows не работает

1 Ответ

0 голосов
/ 07 июля 2019

Эй, я не знаю, поможет ли это вам, но я написал плагин для ChartJS , который делает именно то, что вы просите.Вы можете адаптировать исходный код в repo для своих собственных нужд.Вот соответствующий фрагмент:

  /**
   * Draw the line height annotation to the highest data point on the chart.
   * @param {int} x horizontal coordinate on canvas
   * @param {int} bottomY bottom Y dimension of the chart
   * @param {float} highestDataY highest possible Y value on the chart, taking padding and border offsets into consideration.
   */
  drawLineHeightAnnotation(x, bottomY, highestDataY) {
    let ctx = this.ctx;
    let options = this.options;

    ctx.save();
    ctx.beginPath();
    if (!options.noDash) {
      ctx.setLineDash([10, 10]);
    }
    ctx.moveTo(x, highestDataY);
    ctx.lineTo(x, bottomY);
    ctx.lineWidth = options.lineWeight ? options.lineWeight : 1.5;
    ctx.strokeStyle = options.color ? options.color : "#000";
    ctx.stroke();
    ctx.restore();
  }
...