【问题标题】:Change the length of the labels on the x-axis in jpgraph (Charts)更改 jpgraph 中 x 轴上标签的长度(图表)
【发布时间】:2012-07-30 13:40:57
【问题描述】:

我已经使用 jpgraph 创建了一个图表 - 但是由于我的 x 轴上标签的长度,它可以工作,一些文本被“截断”并且不可见。我创建了一个自定义函数来使用换行符,但即便如此,它仍然会修剪图表上一个标签上的一些字符。

是否有一种方法可以实际定义 x 轴标签的实际长度,例如以像素为单位设置宽度?谢谢

        // Create the graph. These two calls are always required
    $graph = new Graph(1000,500,'auto');
    $graph->SetScale("textlin");

    //$theme_class="DefaultTheme";
    //$graph->SetTheme(new $theme_class());

    // set major and minor tick positions manually
    $graph->yaxis->SetTickPositions(array(0,1,2,3,4,5), array(0.5,1.5,2.5,3.5,4.5));
    $graph->SetBox(false);

    //$graph->ygrid->SetColor('gray');
    $graph->ygrid->SetFill(false);
    $graph->xaxis->SetLabelAngle(90); // 45 degrees angle
    $graph->xaxis->SetTickLabels($new_labels);
    $graph->yaxis->HideLine(false);
    $graph->yaxis->HideTicks(false,false);

    // Create the bar plots
    $b1plot = new BarPlot($data);

    // ...and add it to the graPH
    $graph->Add($b1plot);        

    $b1plot->SetColor("white");
    $b1plot->SetFillGradient("#4B0082","white",GRAD_LEFT_REFLECTION);
    $b1plot->SetWidth(45);
    $graph->title->Set("Bar Gradient(Left reflection)");

    // Display the graph
    $graph->Stroke();

【问题讨论】:

  • 虽然 jpgraph 是基于 php 的,但这不是 PHP 的问题。因此,我删除了 PHP 标记。

标签: charts jpgraph


【解决方案1】:

我认为您不能设置标签的长度。对于旋转图,您需要使用$graph->setMargin(a,b,c,d);$graph->Set90AndMargin(a,b,c,d); 设置图的边距。 a - 左,b - 右,c - 上,d - 下边距。

查看关于这些函数的文档可能会与旋转图有点混淆。

【讨论】:

    【解决方案2】:

    想通了(几乎) 以防万一其他人需要帮助,请使用以下内容:

    $graph->xaxis->SetLabelAlign('right','center','right');
    

    【讨论】:

      猜你喜欢
      • 2013-01-11
      • 1970-01-01
      • 1970-01-01
      • 2012-12-24
      • 1970-01-01
      • 2015-11-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多