gpt4 book ai didi

javascript - JS - 如何在 Google Graphs (slantedText) 上旋转标签 (hAxis)?

转载 作者:行者123 更新时间:2023-11-29 18:02:08 26 4
gpt4 key购买 nike

长期以来,我一直在尝试简单地在下图中旋转我的 hAxis。尝试了下面解释的几种解决方案!不敢相信这么简单的事情似乎很难做到。源代码如下:

<html>

<title>VM Allocation Performance</title>
<meta http-equiv="refresh" content="30">

<head>



<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">

google.load("visualization", "1", {packages:["bar"]});
google.setOnLoadCallback(drawChart);



function drawChart() {
var data = google.visualization.arrayToDataTable([
['09/12/2015 10:00:00',3.52],['09/12/2015 10:30:00',7.56],['09/12/2015 11:00:00',8.99],['09/12/2015 11:30:00',4.93],['09/12/2015 12:00:00',10.26],['09/12/2015 12:30:00',9.82],['09/12/2015 13:00:00',12.62],['09/12/2015 13:30:00',9.07],['09/12/2015 14:00:00',4.94],['09/12/2015 14:30:00',8.98],['09/12/2015 15:00:00',7.85],['09/12/2015 15:30:00',3.59],['09/12/2015 16:00:00',5.64]],true);


var options = {
chart: {
title: 'VM Allocation',
subtitle: 'Since Shift Start',
}
//I tried with slantedText: true here but while my graph was rendering, labels were not rotated!
};

var chart = new google.charts.Bar(document.getElementById('chart_div'));
chart.draw(data, google.charts.Bar.convertOptions(options));
}

</script>

</head>

<body>
<div id='chart_div' style='width: 450px; height: 400px;'></div>
</body>

</html>

到目前为止,这是我尝试过的:

我阅读了 Google 文档,相应地更改了我的代码(因为它是一个“ Material ”图等...)但仍然没有。

我尝试使用与此 jsfiddle 相同的 hAxis block 我发现,运气不好。

我进入了更多细节并在 Google doc 上看到“slantedText”选项仅适用于离散 Axis ,因此我想我必须将我的 hAxis 类型从日期/时间更改为字符串,我尝试过但没有成功。

我继续尝试使用 this来自 SO 的解决方案,虽然我仍然可以呈现图表,但我的日期/时间标签仍然没有完全显示(这就是我想要旋转它们的原因)。

有人可以帮忙吗?

最佳答案

更改为柱形图而不是条形图。参见 http://jsfiddle.net/Swtv3/51/

function drawChart() {
var data = google.visualization.arrayToDataTable([
['09/12/2015 10:00:00',3.52],['09/12/2015 10:30:00',7.56],['09/12/2015 11:00:00',8.99],['09/12/2015 11:30:00',4.93],['09/12/2015 12:00:00',10.26],['09/12/2015 12:30:00',9.82],['09/12/2015 13:00:00',12.62],['09/12/2015 13:30:00',9.07],['09/12/2015 14:00:00',4.94],['09/12/2015 14:30:00',8.98],['09/12/2015 15:00:00',7.85],['09/12/2015 15:30:00',3.59],['09/12/2015 16:00:00',5.64]],true);


var options = {
chart: {
title: 'VM Allocation',
subtitle: 'Since Shift Start',
},
chartArea: {
top: 28,
height: '40%'
},
hAxis: {
title: 'Sources',
slantedText: true
}
//I tried with slantedText: true here but while my graph was rendering, labels were not rotated!
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart'));
chart.draw(data, options);
}

google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);

enter image description here

关于javascript - JS - 如何在 Google Graphs (slantedText) 上旋转标签 (hAxis)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34183368/

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