Draw a line on the canvas

TeeChart for Javascript for the HTML5 Canvas
Post Reply
myTeeChart219
Newbie
Newbie
Posts: 6
Joined: Tue Apr 11, 2017 12:00 am

Draw a line on the canvas

Post by myTeeChart219 » Tue May 16, 2017 8:50 am

Hi

I've looked at the Canvas demo to draw a rectangle, but I can't see how to draw a line? Is there a specific function that I can't find?

Please could you point me to the documentation or offer some basic code to draw a horizontal line on a line chart.

Many thanks

Yeray
Site Admin
Site Admin
Posts: 8518
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Draw a line on the canvas

Post by Yeray » Tue May 16, 2017 1:13 pm

Hello,

You have to use the stroke as explained here.
Here a simple example using a chart:

Code: Select all

            var myFormat = new Tee.Format(Chart1);
            myFormat.stroke.fill = "rgb(250, 83, 55)";

            Chart1.ondraw=function() {

                var x1 = Chart1.axes.bottom.calc(2),
                    y1 = Chart1.axes.left.calc(70),
                    x2 = Chart1.axes.bottom.calc(4),
                    y2 = Chart1.axes.left.calc(40);

                Chart1.ctx.beginPath();
                Chart1.ctx.moveTo(x1, y1);
                Chart1.ctx.lineTo(x2, y2);

                myFormat.stroke.prepare();
                Chart1.ctx.stroke();
            }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply