gpt4 book ai didi

charts - 谷歌图表——轴值重叠以及如何避免

转载 作者:行者123 更新时间:2023-12-03 22:15:26 25 4
gpt4 key购买 nike

enter image description here

如何避免谷歌图表中的这个轴重叠?我正在处理一个大型数据集,但不确定如何解决这个问题。我为 x 轴使用了大量日期。我用于图表的选项是

var options = {
tooltip: {
trigger: 'both',
},
width: 1900,
height: 400,
vAxis: { 'title': 'Volume' },
crosshair: { trigger: 'both'}
};

编辑::
PHP 创建容器
if( isset($db_graph_query)){
while($row = mysqli_fetch_array($db_graph_query)) {
$rowcount2++;
// removed the hard coded column set and made it driven off of the array below
// could have pulled it from the $cols array above, but there might be columns that we don't wish to show
echo " <tr>";
$colindex = 0;
foreach( $cols as $column_name ) {
$style = "";
$val = $row[$column_name];
if ( isset($column_callback)) {
$style=$column_callback($colindex, $val);
}
if ($colindex == 0) {
echo "<td style='text-align: left; width: 1pt;'><a href='#' class='toggle' onClick='drawChart(\"$val\");'>$val</a></td>";
$tempval = $val;
} else {
echo "<td $style>$val</td>";
}
$colindex++;
}
echo "</tr>";
echo "<tr class='tablesorter-childRow'>";
echo "<td colspan='12'>";
echo "<div id='$tempval' style='height: 400px;'></div>";
echo "</td>";
echo "</tr>";
}
}

编辑::
绘制图表脚本,创建图表选项,从 SQL DB 中获取数据并添加到数据中:
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
function drawChart(inputname) {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('string', 'RunDate');
data.addColumn('number', 'Runs');
data.addColumn('number', 'Fails');
data.addRows([
<?php
$dbName = "mydb";
$config = parse_ini_file("configfile.ini",true);
$dbUser = $config["DB"]["db_user"];
$dbServer = $config["DB"]["db_ip"];
$dbPassword = $config["DB"]["db_pass"];

$con = mysql_connect($dbServer, $dbUser, $dbPassword);

if (!$con) {
die('Could not connect: ' . mysql_error());
}

mysql_select_db($dbName, $con);
$sql = mysql_query("SELECT * From MyTestTable");

$output = array();

while($row = mysql_fetch_array($sql)) {
// create a temp array to hold the data
$temp = array();

// add the data
$temp[] = '"' . $row['Name'] . '"';
$temp[] = '"' . $row['RunDate'] . '"';
$temp[] = (int) $row['Runs'];
$temp[] = (int) $row['FailCount'];
// implode the temp array into a comma-separated list and add to the output array
$output[] = '[' . implode(', ', $temp) . ']';
}
// implode the output into a comma-newline separated list and echo
echo implode(",\n", $output);

mysql_close($con);
?>
]);
var view = new google.visualization.DataView(data);
view.setRows(data.getFilteredRows([
{column: 0, value: inputname}
]));
view.setColumns([1,2,3]);

var options = {
tooltip: {
trigger: 'both',
},
vAxis: { 'title': 'Volume' },
crosshair: { trigger: 'both'},
width: 1900,
height: 400
};

var chart = new google.visualization.LineChart(document.getElementById(inputname));
chart.draw(view, options);
}
</script>

最佳答案

尝试使用倾斜文本选项...

hAxis: {slantedText: true}

关于charts - 谷歌图表——轴值重叠以及如何避免,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51289639/

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