【问题标题】:jpgraph and x axisjpgraph 和 x 轴
【发布时间】:2012-03-13 08:54:08
【问题描述】:

我尝试解决 jpGraph 中的一个问题。正如您在上面看到的,我的图表和 x 轴由时间组成。但也有像 20 30 40 50 60 这样的数字。我可以隐藏它们吗?有没有办法做到这一点?

这是我的代码

<?php // content="text/plain; charset=utf-8"
require_once ('jpgraph.php');
require_once ('jpgraph_line.php');

ini_set("display_errors","off");
$getJson = file_get_contents("http://borsa.doviz.com/hisse_grafik_ajax/XU100/hisse/minute/json",false);

$j = json_decode($getJson);
$i = 0;
$datay1 = array();
$datay2 = array();
$max = 0;
foreach($j as $result)
{
    $datay1[]=$result->KAPANIS;
    $arr = explode(" ",$result->TARIH);
    $arr2 = explode(":",$arr[1]);
    $datay2[]=$arr2[0] . ":" . $arr2[1];
    if($arr[0] > $max)
        $max = $arr[0];
}


// Setup the graph
$graph = new Graph(450,300);
$graph->SetScale('intlin',0,0,0,70);


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




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


// For background to be gradient, setfill is needed first.
$graph->ygrid->SetFill(true,'#FFFFFF@0.5','#FFFFFF@0.5');
$graph->SetBackgroundGradient('#F0F8FF', '#FFFFFF', GRAD_HOR, BGRAD_PLOT);

for($i = 0; $i < sizeof($datay2); $i++)
{
    if($datay2[$i] == ":")
        $datay2[$i] = "";
}





$graph->xaxis->SetTickLabels($datay2);
$graph->xaxis->HideLastTickLabel();

for($i = 0; $i < sizeof($datay2); $i++)
{
    if($datay2[$i] == ":")
        $datay2[$i] = "";
}





// Create the line
$p1 = new LinePlot($datay1);
$graph->Add($p1);



$p1->SetFillGradient('#00FF7F','#FFFFFF');
$p1->SetColor('#aadddd');



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

?>

【问题讨论】:

    标签: php jpgraph


    【解决方案1】:

    我真的花了很多时间来解决它。 我首先找到了名为 jpgraph 的类。

    找到这个地方

     // ticks_label has an entry for each data point and is the array
                    // that holds the labels set by the user. If the user hasn't
                    // specified any values we use whats in the automatically asigned
                    // labels in the maj_ticks_label
                    if (isset($this->ticks_label[$i * $m])) {
                        $label = $this->ticks_label[$i * $m];
                    } else {
                        if ($aAbsLabel) {
                            $label = abs($this->scale->ticks->maj_ticks_label[$i]);
                        } else {
                            $label = $this->scale->ticks->maj_ticks_label[$i];
    

    并添加

    if($label == 60)
                                  $label = "";
                            elseif ($label == 50)
                                 $label = "";
                             elseif ($label == 40)
                                 $label = "";
                              elseif ($label == 30)
                                 $label = "";
                               elseif ($label == 20)
                                 $label = "";
                                elseif ($label == 10)
                                 $label = "";
    

    【讨论】:

      猜你喜欢
      • 2012-12-24
      • 2014-03-06
      • 2012-09-06
      • 1970-01-01
      • 2015-11-05
      • 1970-01-01
      • 2013-01-11
      • 2014-06-08
      • 2013-04-29
      相关资源
      最近更新 更多