为什么titleTextStyle不能与Google Charts中的title选项一起使用?

问题描述 投票:1回答:1

我正在使用Google Charts创建一个简单的条形图,并从Mysql Database中获取数据。图表显示正确,但是我无法设置图表标题的格式。我已经提到过许多站点,并且我确信'titleTextStyle'的语法是可以的。但是标题不会随选项一起改变。有人可以告诉我问题出在哪里吗?我在下面附上了我的完整代码。预先感谢。

<?php 

    include("toconnect.php");
    $result = mysqli_query($connection,"SELECT Product_name,COUNT(*)  FROM Items_Sold GROUP BY Product_name");

?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load('current', {'packages':['bar']});
      google.charts.setOnLoadCallback(drawChart);

      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Product Name', 'Frequency'],
          <?php 
            if(mysqli_num_rows($result) > 0){
                    while($row = mysqli_fetch_array($result))
                    {
                            echo "['".$row["Product_name"]."','".$row["COUNT(*)"]."'],";
                    }
            }
          ?>
        ]);

        var options = {
          chart: {
            title: "Frequently Bought items",titleTextStyle:{ color: '#007DB0',fontName: "Times",fontSize: 60,bold: true},
        }
        };
        var chart = new google.charts.Bar(document.getElementById('columnchart_material'));

        chart.draw(data, google.charts.Bar.convertOptions(options));
      }
    </script>
  </head>
  <body>
    <div id="columnchart_material" style="width: 800px; height: 500px;display:inline-block;"></div>
  </body>
</html>
php html charts google-visualization
1个回答
0
投票

您正在使用材料图表...

google.charts.Bar

无法在材料图表中使用的功能列表,可以在这里找到...

Tracking Issue for Material Chart Feature Parity #2143

其中包括...

titleTextStyle


尝试使用经典图表代替...

google.visualization.ColumnChart

带有选项...

theme: 'material'

© www.soinside.com 2019 - 2024. All rights reserved.