How can I create a horizontal scrolling Chart.js line chart with a locked y axis?

后端 未结 7 1827
生来不讨喜
生来不讨喜 2020-11-29 00:39

I\'d like to create a line chart with Chart.Js but have the Y-Axis not move when I scroll.

I\'m assuming I can use a fixed width, and put i

7条回答
  •  难免孤独
    2020-11-29 00:51

    To add to Emma Louise's solution above (I don't have the reputation to comment), I found that if I filled the rectangle with a color before drawing the image, the overlay canvas is opaque. Then you don't need to worry about clearing the rectangle, either onProgress or onComplete.

        targetCtx.fillStyle = 'white'
        targetCtx.fillRect(0, 0, copyWidth * scale, copyHeight * scale);
    

    Also, maybe it's because my devicePixelRatio is one, but these two lines caused the text in my chart to be all fuzzy. It looks fine when I remove them.

        targetCtx.canvas.style.width = `${copyWidth}px`;
        targetCtx.canvas.style.height = `${copyHeight}px`;
    

提交回复
热议问题