Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何修复chart js中的模糊图表问题?_Javascript_Php_Jquery_Charts_Bar Chart - Fatal编程技术网

Javascript 如何修复chart js中的模糊图表问题?

Javascript 如何修复chart js中的模糊图表问题?,javascript,php,jquery,charts,bar-chart,Javascript,Php,Jquery,Charts,Bar Chart,我正在使用chart.js创建条形图。但是这个图表在我的屏幕上看起来很模糊。下面是我的html和js代码: <canvas id="myChart" style="padding-left: 0;padding-right: 0;margin-left: auto; margin-right: auto; display: block;width: 90%;height:350px;"></canvas> 创建图表栏的Js代码: window.onload = fu

我正在使用chart.js创建条形图。但是这个图表在我的屏幕上看起来很模糊。下面是我的html和js代码:

<canvas id="myChart" style="padding-left: 0;padding-right: 0;margin-left: auto; margin-right: auto; display: block;width: 90%;height:350px;"></canvas>

创建图表栏的Js代码:

window.onload = function () {       
var data = {
labels: [],
datasets: [
    {
        label: "My First dataset",
        fillColor: "rgba(220,220,220,2)",
        strokeColor: "rgba(220,220,220,2)",
        pointColor: "rgba(220,220,220,2)",
        pointStrokeColor: "#fff",
        pointHighlightFill: "#fff",
        pointHighlightStroke: "rgba(220,220,220,2)"
    },
    {
        label: "My Second dataset",
        fillColor: "rgba(12, 18, 51, 1)",
        strokeColor: "rgba(12, 18, 51, 1)",
        pointColor: "rgba(12, 18, 51, 1)",
        pointStrokeColor: "#fff",
        pointHighlightFill: "#fff",
        pointHighlightStroke: "rgba(12, 18, 51, 1)"
    }
]
};

var ctx = jQuery("#myChart")[0].getContext('2d');
var options = {   
scaleBeginAtZero : true,   
scaleShowGridLines : true,    
scaleGridLineColor : "rgba(0,0,0,.05)",  
scaleGridLineWidth : 1,    
scaleShowHorizontalLines: true,   
scaleShowVerticalLines: false,   
barShowStroke : true,
barStrokeWidth : 2,   
barValueSpacing : 10,    
barDatasetSpacing : 1,

legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].fillColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"

}
var myLineChart = new Chart(ctx).Bar(data, options);
<?php foreach($resultGraph as $share){?>

myLineChart.addData([<?php echo $share->shCOunt;?>, <?php echo $share->tt;?>], "<?php echo $share->post_date1;?>"); 
<?php } ?>

//myLineChart.addData([30, 50], "January");

}   

</script>
window.onload=function(){
风险值数据={
标签:[],
数据集:[
{
标签:“我的第一个数据集”,
填充颜色:“rgba(2202,2)”,
strokeColor:“rgba(2202,2)”,
点颜色:“rgba(2202,2)”,
pointStrokeColor:“fff”,
pointHighlightFill:“fff”,
pointHighlightStroke:“rgba(2202,2)”
},
{
标签:“我的第二个数据集”,
fillColor:“rgba(12,18,51,1)”,
strokeColor:“rgba(12,18,51,1)”,
pointColor:“rgba(12,18,51,1)”,
pointStrokeColor:“fff”,
pointHighlightFill:“fff”,
pointHighlightStroke:“rgba(12,18,51,1)”
}
]
};
var ctx=jQuery(“#myChart”)[0].getContext('2d');
变量选项={
scaleBeginAtZero:对,
scaleShowGridLines:对,
scaleGridLineColor:“rgba(0,0,0,05)”,
scaleGridLineWidth:1,
缩放水平线:对,
ScaleShowVerticalline:错误,
barShowStroke:是的,
杆行程宽度:2,
barValueSpacing:10,
barDatasetSpacing:1,
legendTemplate:“
    ” } var myLineChart=新图表(ctx).Bar(数据、选项); 添加数据([,],“”); //myLineChart.addData([30,50],“一月”); }

    尝试向x坐标值添加0.5。请参见对这一点的解释,我今天在Chrome最新版本上遇到了这一点,真的浪费了3个小时去追赶它。 最后发现,只有当浏览器URL是带有某个端口的localhost时,才会出现问题。e、 g

    我在虚拟主机上浏览了我的应用程序(作为修改主机文件),问题消失了。:-)


    希望这些信息能帮助开发者复制和修复错误

    确保不要向canvas元素添加一些css。 在我的例子中,我发现我正在向canvas元素添加border属性,这是导致文本和条模糊的原因

    不要使用这样的东西:

    canvas { border: 1px solid #000 }
    
    或者使用您的示例中的id:

    #myChart { border: 1px solid #000 }
    

    可能是笔划宽度

    请检查您推送的数据集

    var arraytable = [
        [
            {label: "Sector", type: 'string'},
            {label: "Exposure", type: 'number'},
            {role: 'style', type: 'string'},
        ],
        ['Energy', 0.32, 'color: #005695; stroke-width: 0']
    ];
    var datatable = google.visualization.arrayToDataTable(arraytable);
    

    我在3.2.1版上遇到了这个问题

    可能我有这个问题,因为我在模态窗口中显示图表。在我的例子中,我将CSS从#myChart移动到父元素,现在图表变得清晰:

    <style>
      .graph-wr {
        height: 600px;
        max-height: 600px;
        max-width: 100%;
        position: relative;
        width: 1650px;
      }
    </style>
    
    <div class="graph-wr">
      <canvas id="myChart"></canvas>
    </div>
    
    
    .图形wr{
    高度:600px;
    最大高度:600px;
    最大宽度:100%;
    位置:相对位置;
    宽度:1650px;
    }
    
    这为我解决了模糊问题。我还是会再深入一点。我还将查看,因为我看到它有一些特定的选项


    也是Chart.js中的CodePen示例。

    这会使绘制浮点值变得更加模糊吗?如果是这种情况,你应该先尝试四舍五入,然后再加上0.5。否则,它们的边缘会流血,因此看起来很模糊。我不明白你在说什么。如果你的x坐标值来自这个
    $share->shCOunt,你能给我解释一下,告诉我在我的代码中应该在哪里添加0.5吗,我建议您可以尝试以下内容:
    。首先确保您的数据点是一个整数,然后再加上0.5。@1请在这个实时测试用例中演示一下Gonza好吗?你看到了吗?我在制作中也面临着这个问题。@ShrutikaPatil你是如何解决这个问题的?我们在生产中遇到了与某些产品相同的问题subdomains@Mischa我从canvas标签中删除了CSS,并将其添加到上面的div中