خرید بک لینک

Vote count: 0

I'm trying to draw this chart-like shape on an html canvas:

0

100                                     .
                                        .
200                             .       .
                                        .
300                     .               .
                                        .
400     .       .                       .
                                        .
500     .................................

I can't see anything wrong with my shape's co-ordinates:

(0, 500), (0, 400), (100, 400), (200, 300), (300, 200), (400, 100), (400, 500)

Html/js:

<html>
    <head>
        <script type="text/javascript">
            function drawSteps(heights) {
                var y = 500;
                var steps = document.getElementById('steps').getContext('2d');
                steps.fillStyle = '#C3EDBD';
                steps.beginPath();
                steps.moveTo(0, y);

                var x = 0;
                for (var i = 0; i < heights.length; i++) {
                    console.log(x.toString() + ', ' + (y - heights[i]).toString());
                    steps.lineTo(x, y - heights[i]);
                    x += 100;
                }

                steps.lineTo(x, 500);
                steps.lineTo(0, 500);
                steps.closePath();
                steps.fill();
            }
        </script>
    </head>
    <body>
        <canvas id="steps"></canvas>
        <script type="text/javascript">
            drawSteps([100, 100, 200, 300, 400]);
        </script>
    </body>
</html>

Nothing gets printed on the screen but canvas consumes a 300x150px placeholder.

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 4 مرداد 1395 ساعت: 6:12

صفحه بندی