首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ChartJS/ ChartJS-plugin注解设置垂直线高度

ChartJS/ ChartJS-plugin注解设置垂直线高度
EN

Stack Overflow用户
提问于 2019-03-04 20:23:22
回答 1查看 1.9K关注 0票数 0

可以在图表js中设置垂直线的高度吗?

例如这个例子:https://jsfiddle.net/caj89x6L/

代码语言:javascript
复制
{
  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窗口不工作

EN

回答 1

Stack Overflow用户

发布于 2019-07-07 05:47:40

嘿,我不知道这是否仍然对你有帮助,但是我写了一个plugin for ChartJS,它完全按照你的要求做了。您可以根据自己的需要调整repo中的源代码。下面是相关的代码片段:

代码语言:javascript
复制
  /**
   * 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();
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54983206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档