dongni3854 2018-10-19 18:02
浏览 28

JpGraph没有从txt文件中获得正确的结果

I am learning how to use the jpGraph library but when I use their example code I get a different result. 1 is their example and 2 is what my chart produces after I use the code they provided. I think the problem is for some reason the function they provided is just counting how many are in the 0(left) column instead of using the numbers. I am not sure what I did wrong. I have tried changing the right column with the left and it does the same thing.

example chart

require_once ('Libraries/jpgraph/jpgraph.php');
require_once ('Libraries/jpgraph/jpgraph_line.php');
require_once ('Libraries/jpgraph/jpgraph_bar.php');

function readsunspotdata($aFile, &$aYears, &$aSunspots) {
    $lines = @file($aFile,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
    if( $lines === false ) {
        throw new JpGraphException('Can not read sunspot data file.');
    }
    foreach( $lines as $line => $datarow ) {
        $split = preg_split('/[\s]+/',$datarow);
        $aYears[] = substr(trim($split[0]),0,4);
        $aSunspots[] = trim($split[1]);
    }
}

$year = array();
$ydata = array();
readsunspotdata('yearssn.txt',$year,$ydata);

 // Width and height of the graph
$width = 1000; $height = 500;

// Create a graph instance
$graph = new Graph($width,$height);

// Specify what scale we want to use,
// int = integer scale for the X-axis
// int = integer scale for the Y-axis
$graph->SetScale('intint');

// Setup a title for the graph
$graph->title->Set('Sunspot example');

// Setup titles and X-axis labels
$graph->xaxis->title->Set('(year from 1701)');

// Setup Y-axis title
$graph->yaxis->title->Set('(# sunspots)');

// Create the linear plot
$lineplot=new LinePlot($ydata);

// Add the plot to the graph
$graph->Add($lineplot);

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

text file

1700.5   5.0  
1701.5  11.0  
1702.5  16.0  
1703.5  23.0  
1704.5  36.0  
1705.5  58.0  
1706.5  29.0  
1707.5  20.0  
1708.5  10.0  
1709.5   8.0

17012.5   15.0
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题