【问题标题】:jpgraph x axis scalejpgraph x 轴刻度
【发布时间】:2012-12-24 15:12:15
【问题描述】:

我如何告诉 jpgraph 每个月显示 x 轴刻度?我有两张图表,一张显示 1 年的结果,另一张显示从头到尾的结果。在年度图表上,它显示每周结果,我喜欢它,但如果显示更大的日期范围(在我的情况下,从 1.4.2010 到 10.1.2013。它只显示一年一次的刻度,所以我在 1.4.2010、1.4 上打勾.2011, ...

我定义 x 轴属性的代码的重要部分:

$graph->xaxis->SetTickLabels($timestamp);
$graph->xaxis->scale->SetDateAlign(MONTHADJ_1);
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
$graph->xaxis->SetLabelAngle(-45);
$graph->xaxis->SetLabelMargin(2);
$graph->xaxis->SetLabelAlign('left','top');
$graph->xaxis->SetLabelFormatString('d.m.Y',true);
$graph->xaxis->HideFirstLastLabel();

时间戳数组是从mysql日期转换而来的unix时间戳值,时间戳是正确的。我检查了他们。图表中的结果也很好,只是我想要在 x 轴上有更多的刻度。

【问题讨论】:

  • 有一个“解决方法”,计算 30 天内的秒数,并使用 $graph->xaxis->scale->ticks->Set(2592000) 但一个月有或多或少 30 天我在 x 轴上没有相同的日子。
  • 在 DataScaleUtils 库中找到了我的答案。现在一切正常

标签: php jpgraph


【解决方案1】:

为了回答我自己的问题并将其关闭,这是我添加的内容(结合旧的 xaxis 属性):

require_once ('jpgraph/jpgraph_utils.inc.php');

$dateUtils = new DateScaleUtils();
list($tickPos,$minTickPos) = $dateUtils->getTicks($timestamp,DSUTILS_MONTH1);

$graph->xaxis->SetTickPositions($tickPos,$minTickPos);
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
$graph->xaxis->SetLabelAngle(-45);
$graph->xaxis->SetLabelMargin(2);
$graph->xaxis->SetLabelAlign('left','top');
$graph->xaxis->SetLabelFormatString('d.m.Y',true);
$graph->xaxis->HideFirstLastLabel();

我还把图表的比例改为 intlin,之前是 datlin。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-19
    • 2021-04-03
    • 1970-01-01
    相关资源
    最近更新 更多