繁体   English   中英

JPGraph (php) 线图 - 比例问题

[英]JPGraph (php) line plot - problems with scale

我正在尝试使用 jpgraph 创建折线图。

我在显示图形时遇到问题 - 我收到的错误消息是:“JPGraph 错误:25044 = 无法使用自动缩放,因为无法确定 y 轴的有效最小值/最大值(仅空值)。”

我的代码如下:

<?php // content="text/plain; charset=utf-8"
session_start();
require_once ('../includes/jpgraph/src/jpgraph.php');
require_once ('../includes/jpgraph/src/jpgraph_line.php');
// Some data
$datay1 = $_SESSION['userValues'];
$d = array();
for($i = 0; $i < 30; $i++) 
    $d[] = date("d", strtotime('-'. $i .' days'));

// Create the Line Graph. 
$graph = new Graph(300,250);
$graph->SetScale("textlin");

$theme_class=new UniversalTheme;

$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(false);
$graph->title->Set('Your Performance:');
$graph->SetBox(false);

$graph->img->SetAntiAliasing();

$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);

$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xaxis->SetTickLabels($d);
$graph->xgrid->SetColor('#E3E3E3');

// Create the first line
$p1 = new LinePlot($datay1);
$graph->Add($p1);
$p1->SetColor("#6495ED");
$p1->SetLegend('Line 1');

$graph->legend->SetFrameWeight(1);

// Output line
$graph->Stroke();

?>

我想我可能在为 x 轴分配日期时出错了(我想显示过去 30 天)。 数据使用会话传递并经过测试以确保它包含实际数据。

谢谢

尝试执行以下操作并查看该网页http://jpgraph.net/doc/howto2.php

像往常一样,我们希望确保 X 轴的刻度完全覆盖我们的函数,因此我们需要找出沿 X 轴的最小值和最大值,并使用它们手动设置刻度。

$n = count($datax);
$xmin = $datax[0];
$xmax = $datax[$n-1];

现在是设置基本图形的时候了。 这与我们之前所做的非常相似,唯一的区别是我们使用 SetMajtickPosition() 方法来避免我们不感兴趣的次要刻度的 NULL 参数。

$graph->SetScale('linlin',0,0,$xmin,$xmax);
$graph->title->Set('Example with manual tick labels');
$graph->title->SetFont(FF_ARIAL,FS_NORMAL,12);
$graph->xaxis->SetPos('min');
$graph->xaxis->SetMajTickPositions($tickPositions,$tickLabels);
$graph->xaxis->SetFont(FF_TIMES,FS_NORMAL,10);
$graph->yaxis->SetFont(FF_TIMES,FS_NORMAL,10);
$graph->xgrid->Show();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM