gpt4 book ai didi

javascript - Segoe 字体未添加到谷歌图表中

转载 作者:行者123 更新时间:2023-12-02 22:13:39 25 4
gpt4 key购买 nike

我想将 Segoe UI 字体添加到 Google 条形图。我尝试使用 fontName 属性添加它。但它在“网络”选项卡中显示错误。在控制台中打印此错误:

加载资源失败:服务器响应状态为 400 ()

您可以看到代码here .

google.charts.load('current', {packages: ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawBarColors);

function drawBarColors() {
var data = google.visualization.arrayToDataTable([
['City', '2010 Population', '2000 Population'],
['New York City, NY', 8175000, 8008000],
['Los Angeles, CA', 3792000, 3694000],
['Chicago, IL', 2695000, 2896000],
['Houston, TX', 2099000, 1953000],
['Philadelphia, PA', 1526000, 1517000]
]);

var options = {
title: 'Population of Largest U.S. Cities',
chartArea: {width: '50%'},
colors: ['#b0120a', '#ffab91'],
hAxis: {
title: 'Total Population',
minValue: 0
},
vAxis: {
title: 'City'
},
titleTextStyle: {
color:'#3a3a3a',
fontSize:24,
bold:false,
fontName: "Segoe UI"
},
};
var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

谁能帮我解决这个问题。提前致谢。

最佳答案

您或许可以仅使用 CSS 来完成此操作。如果您想以其他方式进行操作,请告诉我。

google.charts.load('current', {packages: ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawBarColors);

function drawBarColors() {
var data = google.visualization.arrayToDataTable([
['City', '2010 Population', '2000 Population'],
['New York City, NY', 8175000, 8008000],
['Los Angeles, CA', 3792000, 3694000],
['Chicago, IL', 2695000, 2896000],
['Houston, TX', 2099000, 1953000],
['Philadelphia, PA', 1526000, 1517000]
]);

var options = {
title: 'Population of Largest U.S. Cities',
chartArea: {width: '50%'},
colors: ['#b0120a', '#ffab91'],
hAxis: {
title: 'Total Population',
minValue: 0
},
vAxis: {
title: 'City'
},
titleTextStyle: {
color:'#3a3a3a',
fontSize:24,
bold:false
},
};
var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
#chart_div g g text{
font-family:Segoe UI !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

关于javascript - Segoe 字体未添加到谷歌图表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59469524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com