【问题标题】:Use multiple mark styles on one plot line with jpgraph使用 jpgraph 在一条绘图线上使用多种标记样式
【发布时间】:2018-09-08 15:00:27
【问题描述】:

我有一组跨越多个日期的数据。一些数据点需要用不同的样式来标识,以便它们脱颖而出。我可以通过使用不同的标记样式创建 2 条绘图线来近似我需要的内容,但它看起来并不连贯,并且可能会让某些人感到困惑。这是使用该方法的示例。

以上示例中的所有数据点都应连接。问题是

  • 是否可以创建具有不同标记样式的单个绘图线?
  • 如果上述答案是否定的,有没有办法以某种方式“合并”两条绘图线,以便所有点都连接起来?

创建示例图的代码:

<?php
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_date.php';

$line1D = array(1497844800,1498449600,1505102400,1516597200);
$line1Y = array(79.00,76.00,53.00,14.00);
$line2D = array(1504584000,1507521600);
$line2Y = array(9.87,9.93);

$graph = new Graph(640,480);
$graph->clearTheme();
$graph->SetScale('datlin');

$graph->xaxis->SetLabelAngle(60);
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
$graph->xaxis->SetLabelFormatString('m/d/Y',true);
$graph->yaxis->scale->SetGrace(5);

$line1=new LinePlot($line1Y,$line1D);
$line1->SetColor('#4A6EC6');
$line1->SetWeight(2);
$line1->mark->SetFillColor('#4A6EC6');
$line1->mark->SetType(MARK_FILLEDCIRCLE);
$graph->Add($line1);

$line2=new LinePlot($line2Y,$line2D);
$line2->SetColor('#4A6EC6');
$line2->SetWeight(2);
$line2->mark->SetType(MARK_CIRCLE);
$line2->mark->SetColor('#4A6EC6');
$graph->Add($line2);

$graph->Stroke();  // display the graph
?>

【问题讨论】:

    标签: php jpgraph


    【解决方案1】:

    在一条线上有不同标记的方法是创建第三条线,它只是没有任何标记的线。然后将具有标记的当前行更改为散点图,以便仅添加带有所需标记的点。当这 3 个东西被绘制在一起时,2 个散点图和一条线,它们组合成一条带有不同标记的线。

    按要求工作的修改后的代码是:

    <?php
    require_once 'jpgraph/jpgraph.php';
    require_once 'jpgraph/jpgraph_line.php';
    require_once 'jpgraph/jpgraph_date.php';
    require_once 'jpgraph/jpgraph_scatter.php';
    
    $line1D = array(1497844800,1498449600,1505102400,1516597200);
    $line1Y = array(79.00,76.00,53.00,14.00);
    $line2D = array(1504584000,1507521600);
    $line2Y = array(9.87,9.93);
    
    $line3D = array_merge($line1D,$line2D);
    $line3Y = array_merge($line1Y,$line2Y);
    
    $graph = new Graph(640,480);
    $graph->clearTheme();
    $graph->SetScale('datlin');
    
    $graph->xaxis->SetLabelAngle(60);
    $graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
    $graph->xaxis->SetLabelFormatString('m/d/Y',true);
    $graph->yaxis->scale->SetGrace(5);
    
    $line1=new ScatterPlot($line1Y,$line1D);
    $line1->SetColor('#4A6EC6');
    $line1->SetWeight(2);
    $line1->mark->SetFillColor('#4A6EC6');
    $line1->mark->SetType(MARK_FILLEDCIRCLE);
    $graph->Add($line1);
    
    $line2=new ScatterPlot($line2Y,$line2D);
    $line2->SetColor('#4A6EC6');
    $line2->SetWeight(2);
    $line2->mark->SetType(MARK_CIRCLE);
    $line2->mark->SetColor('#4A6EC6');
    $graph->Add($line2);
    
    $line3=new LinePlot($line3Y,$line3D);
    $line3->SetColor('#4A6EC6');
    $line3->SetWeight(2);
    $graph->Add($line3);
    
    $graph->Stroke();  // display the graph
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-27
      • 1970-01-01
      • 2018-02-28
      • 2016-09-26
      • 2021-04-12
      • 2021-02-12
      • 2020-05-25
      • 2015-12-17
      相关资源
      最近更新 更多