在Chrome 60中,Chart.js画布元素的高度和宽度为负

罗伯·M

当用户单击另一个图表中的数据时,我正在使用Chart.js显示一些信息。单击图表1时,将创建3个其他图表,这是有问题的图表。它们在Firefox和Edge中都可以正常工作。仅Chrome显示此行为。一旦我调整了屏幕的大小,图表就会自动调整大小,并且看起来不错。

我看着它,它显示了chrome和z-index的问题,但是似乎没有任何地方。

https://bugs.chromium.org/p/chromium/issues/detail?id=155483

关于会发生什么的任何想法?

问题的屏幕截图 控制台的屏幕截图

机队图表点击事件处理程序

//EVENT HANDLERS
$("#fleetSummaryChart").on('click', function (evt) {
    var activeBars = fleetSumChart.getElementsAtEvent(evt);
    var label = activeBars[0]._view.label;
    var tempArr = label.split('(');
    var station = tempArr[0].trim();
    var unit = tempArr[1].replace(')', '').trim();

    stationunit_selected = findIndexByKeyValue(stationUnitDetails, 'StationName', 'UnitName', station, unit) || 0;

    if (typeof (Storage) !== "undefined") {
        //store the selected unit in session storage for loading data in other pages
        sessionStorage.setItem('stationUnitDetails',JSON.stringify(stationUnitDetails[stationunit_selected]));
    }

    setUnitDetails();
    refreshDoughnuts(); <---- THIS IS WHERE THE CHARTS ARE BEING CREATED

    $("#unitDetailsContainer").show();
    $("#rTripContainer").show();
    $("#tTripContainer").show();
    $("#derateContainer").show();

    //THE LINES BELOW WHERE ADDED AND I BELIEVE THIS CORRECTED THE ISSUE


   derateFunctionCht.chart.width = 0;
   reactorTripFunctionCht.chart.width = 0;
   turbineTripFunctionCht.chart.width = 0;

   derateFunctionCht.resize();
   reactorTripFunctionCht.resize();
   turbineTripFunctionCht.resize();

});

function refreshDoughnuts() {
    var tTripsData = getTurbineTripChartData();
    var rTripsData = getReactorTripChartData();
    var drateData = getDerateChartData();

    if((typeof turbineTripFunctionCht === "object") && (turbineTripFunctionCht !== null)){
        turbineTripFunctionCht.destroy();
    }   

    if((typeof reactorTripFunctionCht === "object") && (reactorTripFunctionCht !== null)){
        reactorTripFunctionCht.destroy();
    }
    if((typeof derateFunctionCht === "object") && (derateFunctionCht !== null)){
       derateFunctionCht.destroy();
    }

    turbineTripFunctionCht = new Chart(turbineTripByFunction, {
        type: 'horizontalBar',
        data: tTripsData,
        options: {
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero: true,
                        min: 0,
                        max: 1,
                        fixedStepSize:0.1
                    }
               }]
            },
            legend: {
                labels: {
                    fontColor: '#000',
                    fontStyle: 'bold',
                    fontSize: 15
                }
            }
        }
    });

    Chart.defaults.global.defaultFontColor = '#000';
    Chart.defaults.global.defaultFontSize = 15;
    //Chart.defaults.global.defaultFontStyle = 'bold';

    reactorTripFunctionCht = new Chart(reactorTripByFunction, {
        type: 'horizontalBar',
        data: rTripsData,
        options: {
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero:true
                    }
                }]
            },
            legend: {
                labels: {
                    fontColor: '#000',
                    fontStyle: 'bold',
                    fontSize: 15
                }
            }
        }
    });

    derateFunctionCht = new Chart(deratesByFunction, {
        type: 'horizontalBar',
        data: drateData,
        options: {
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero: true
                    }
                }]
            },
            legend: {
                labels: {
                    fontColor: '#000',
                    fontStyle: 'bold',
                    fontSize:15
                }
            }
        }
    });

}
彼得·范德伦(Peter Van Drunen)

几周前在使用Chart.js时遇到了类似的问题。对我来说,它是“图表”选项中的“响应式”选项,导致其尺寸调整不正确。一种解决方案是在使用jQuery创建画布后立即立即手动调整其大小,但是除非您提供负责初始化图表的代码,否则很难确定。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在pygame中处理宽度和高度为负的矩形

画布无法显示正确的宽度和高度chart.js

元素的宽度在FF和IE中为小数,而在Chrome中为整数

在Chrome的TD中,输入框大小调整的边框在TD内的高度和宽度为100%

在angular-chart.js模块中更改宽度和高度

Chrome中滚动时画布的负Z索引问题

Chart.js饼图未显示在Google Chrome画布中

在Chrome中打开一个具有特定宽度和高度的新HTML点击

使用JavaScript获取图像的实际宽度和高度?(在Safari / Chrome中)

HTML5中的画布宽度和高度

如何在反应中获得正确的画布宽度和高度?

为什么我在chrome dev工具性能面板中获得30 fps,但JS和React都说是60?

在Android Studio中隐藏高度和宽度为零的View元素

无法将高度设置为display:firefox中的table元素,适用于chrome

图片高度:Chrome中为0,但Firefox中为0

如何在 d3.js 中为这张地图设置高度和宽度

从旋转元素中查找元素的实际高度和宽度

从模型中获取画布高度和宽度并使用这些尺寸创建画布

锁定屏幕后,画布元素在Chrome中不可见

Chrome中的CSS输入高度

Fabric js - 将画布宽度和高度设置为 100%

Chart.js:不遵守饼图的宽度和高度

chrome和Firefox中的画布边框变形

无法在Chrome中设置表格页脚元素的高度

在chrome中设置输入type ='file'元素的高度

在Chrome和Safari中更改空间和宽度

检查Chrome中的悬停元素?

页面元素在Chrome中消失

使用JavaScript在Rems中设置元素的高度和宽度