@kiron278

JСanvas, ошибка «Cannot read property 'text' of undefined». Из-за чего возникает ошибка?

Рисую текст на canvas в помощью библиотеки jCanvas. При исполнении метода printCanvas.drawText выдает ошибку Cannot read property 'text' of undefined.

var products=canvas.getLayerGroup('products');
        if(products!==undefined)
        {
            for(var i=0; i<products.length; i++) {

                var width = products[i].width
                var height = products[i].height;
                var x = products[i].x;
                var y = products[i].y;

                printCanvas.drawRect({
                    layer: true,
                    groups: ['textrect'],
                    strokeStyle: '#444',
                    fillStyle: '#ddd',
                    strokeWidth: 8,
                    x: x, y: y,
                    width: width,
                    height: height,
                    cornerRadius: 10,
                    translateX: canvasWidth
                });

                var title = "Название: "+products[i].data['title'];
                var vendor_code="Вендор: "+products[i].data['vendor_code'];
                var count="Штук: "+products[i].data['count'];

                // var stringLength = canvas.measureText(title).width;
                var stringHeight = 38;//printCanvas.measureText(title).height*3;

               /* console.log(products[i].data['title']);
                console.log(products[i].x);
                console.log(products[i].y);
                console.log(products[i].width);
                console.log(products[i].height);*/

                printCanvas.drawText({
                    layer: true,
                    groups: ['info'],
                    // fillStyle: '#9cf',
                    strokeStyle: "#fgf",
                    fillStyle: '222',
                    //strokeWidth: 2,
                    x: x-width/2, y: y - height / 2 + stringHeight,
                    fontSize: 38,
                    fontFamily: 'Verdana, sans-serif',
                    text: "dsfdsf",//title,
                    maxWidth:width,
                    align: "info",
                    fromCenter:false,
                    translateX: canvasWidth
                });

                printCanvas.drawText({
                    layer: true,
                    groups: ['info'],
                    // fillStyle: '#9cf',
                    fillStyle: '222',
                    //strokeWidth: 2,
                    x:  x-width/2, y: y - height / 2 + stringHeight*2 + stringHeight  + 5,
                    fontSize: 38,
                    fontFamily: 'Verdana, sans-serif',
                    text: "dfds",//vendor_code,
                    maxWidth:width,
                    align: "left",
                    fromCenter:false,
                    translateX: canvasWidth
                });

                printCanvas.drawText({
                    layer: true,
                    groups: ['info'],
                    // fillStyle: '#9cf',
                    fillStyle: '222',
                    //strokeWidth: 2,
                    x:  x-width/2, y: y - height / 2 + stringHeight * 4+stringHeight  + 5,
                    fontSize: 38,
                    fontFamily: 'Verdana, sans-serif',
                    text: "dfdsf",//count,
                    maxWidth:width,
                    align: "left",
                    fromCenter:false,
                    translateX: canvasWidth
                });
                
            }
        }
        else{
            console.log("Oblom");
        }
  • Вопрос задан
  • 75 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
КРАФТТЕК Санкт-Петербург
от 60 000 до 80 000 ₽
Brightdata Тель-Авив
от 5 500 до 6 500 $
Rocket Брянск
от 60 000 до 100 000 ₽
22 мая 2024, в 02:15
10000 руб./за проект
21 мая 2024, в 23:47
30000 руб./за проект