【问题标题】:How to set min & max range in JPGraph and how to set colors for lines crossing horizontal line?如何在 JPGraph 中设置最小和最大范围以及如何为穿过水平线的线设置颜色?
【发布时间】:2014-03-05 14:55:20
【问题描述】:

我想用 JPGraph 画出这样的东西:

我试过了,但我得到了这样的东西:

问题:

  1. 第一个问题是我无法在 Y 轴上设置最小值和最大值。 (这有时有效,但我不知道为什么)
  2. 而且我不知道如何为穿过水平线的线设置颜色。

JPGraph 可以做到这一点吗?

这是我的代码:

<?php

require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_plotline.php';        

$graph = new Graph(600,300);
$graph->SetMargin(40, 10, 10, 0);
$graph->SetScale("textlin");

$theme_class=new UniversalTheme();
$graph->SetTheme($theme_class);

$sline = new PlotLine(HORIZONTAL,30,'red'); 
$graph->Add($sline);

$sline = new PlotLine(HORIZONTAL,70,'red'); 
$graph->Add($sline);

$graph->SetScale('intlin',0,100);

$line = new LinePlot(json_decode(file_get_contents("http://data.brown.sk/data.json",true)));
$line->SetWeight(1);
$line->SetLegend("test");
$graph->Add($line);

$graph->img->SetAntiAliasing(true);

$graph->title->hide();

$graph->xaxis->Hide();

$graph->xgrid->SetLineStyle("solid");
$graph->xgrid->SetColor('#E3E3E3');

$graph->legend->hide();

$graph->Stroke();

?>

【问题讨论】:

    标签: php jpgraph


    【解决方案1】:

    您可以使用 SetTickPositions() 函数来设置 Y 轴的最小值和最大值。当图表超出范围时,没有函数设置不同的颜色。但是当图表退出某个最小范围时,您可以使用 SetFillFromYMin() 函数填充颜色。它用预定义的颜色填充图形。

    【讨论】:

      猜你喜欢
      • 2014-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-26
      • 2018-07-21
      • 1970-01-01
      • 2020-10-21
      • 1970-01-01
      相关资源
      最近更新 更多