Menu

Problem with mulitple graphs in one Picture

2009-04-19
2012-09-07
  • Jens Wieland

    Jens Wieland - 2009-04-19

    Hello,

    great project, easy to handle, good documentation. but now i got a problem. you can see it at http://www.jenswieland.de/stat.png .
    as you can see, the solid line for the x-grid is not in the right position. it seams that there is a problem with the part:
    $plot->SetPlotAreaWorld(NULL, $min, NULL, $max);

    i calculate ja min an max value +/- 1%.

    here is my code:

    $plot = new PHPlot(800,3400);
    $plot->SetImageBorderType('plain');

    Disable auto-output:

    $plot->SetPrintImage(0);

    There is only one title: it is outside both plot areas.

    $plot->SetTitle("Ressourcen Diagramm: ".$besitzer);

    //// the following part is part of a loop
    // loop start
    $min = round($min-($min/100)1);
    $max = round($max+($max/100)
    1);

    Set up area for first plot:

    $y1 = $y1+$add;
    $y2 = $y2+$add;
    $plot->SetPlotAreaPixels($x1, $y1, $x2, $y2);
    $plot->SetPlotAreaWorld(NULL, $min, NULL, $max);
    //$plot->SetPlotAreaWorld(NULL, 0, NULL, 10000000);

    Do the first plot:

    $plot->SetDataType('text-data');
    $plot->SetDataValues($data);

    $plot->SetDataColors(array('blue'));
    $plot->SetXTickLabelPos('none');
    $plot->SetXTickPos('none');
    $plot->SetYTitle($werte_2[$y]);
    $plot->SetPlotType('linepoints');
    $plot->DrawGraph();
    // loop end

    Output the image now:

    $plot->PrintImage();

    when i use $plot->SetPlotAreaWorld(NULL, 0, NULL, 10000000); instead of $plot->SetPlotAreaWorld(NULL, $min, NULL, $max); i works fine, but every diagramm needs its own min an max value.

    thx for help, i should post more infos, let me know.

    greetings
    Jens

     
    • Alex Doll

      Alex Doll - 2009-04-19

      I don't think I've seen your problem, so I must be doing something differently. My example chart is here:
      http://www.agdconsulting.ca/webtools/phplot_example3.png

      and the code that generated it is:

      $plot->SetImageBorderType('plain');
      $plot->SetPlotType('lines');
      $plot->SetDataType('data-data');
      $plot->SetDataValues($data);
      $plot->SetLineWidths(4);
      $plot->SetDataColors( array('red','blue'));
      $plot->SetLineStyles( array('solid', 'dashed'));
      $plot->SetDefaultDashedStyle('6-4');
      $plot->SetDrawXGrid(true);
      $plot->SetDrawBrokenLines(true);
      $plot->SetDrawYGrid(True); # Is default
      $plot->SetXLabelAngle(0);
      $plot->SetXTickLabelPos('plotdown');
      $plot->SetLabelAngle(0);
      $plot->SetXDataLabelPos('plotdown');
      $plot->SetPlotAreaWorld(0, null, 1, null);
      $plot->SetXTitle("Proportion of samples");
      $plot->SetYTitle($field);
      $plot->SetFont('x_label', 4, 4);
      $plot->SetFont('y_label', 4, 4);
      $plot->SetFont('x_title', 5, 5);
      $plot->SetFont('y_title', 5, 5);
      $plot->DrawGraph();

      Here are some more example plots using similar code:
      http://www.agdconsulting.ca/webtools/phplot_example1.png
      http://www.agdconsulting.ca/webtools/phplot_example2.png

      These two used forked code that allow text to be positioned at the data point on a chart. Let me know if that interests you.

       
    • Jens Wieland

      Jens Wieland - 2009-04-20

      Hello, thanks for reply.
      "text to be positioned at the data point on a chart" ... that would be great. i searched for this, but found nothing.

      but my problem is still there. i updated the graphik. as you can see, every time the x-grap line is at the top, the values of the diagramm before are higher than the current.
      but i got an idea and it works. i added a database entry with all values 0, so every graph starts by 0... but after acouple of month i will not show all data, just a part of 4 weeks. than i have the problem again.

      http://www.jenswieland.de/stat.png <-- 3 entries
      http://www.jenswieland.de/stat2.png <-- start by 0

       
      • Alex Doll

        Alex Doll - 2009-04-20

        Can't provide any more assistance on your problem with the X-axis randomly appearing at the top of the chart. Perhaps I do not observe this because I modified the source code so that the Y-axis always counts by 1, 2 or 5 and not strange decimals? Did you try changing to 'data-data' or any of the other options from my previous post?

        Regarding the modified code to put text on the data points, see here:

        http://www.agdconsulting.ca/webtools/phplot.php

         
    • Jens Wieland

      Jens Wieland - 2009-04-23

      hey Alex, are there any examples how to use your new/added functions ?

       
      • Alex Doll

        Alex Doll - 2009-04-24

        They work exactly the same as the base PHPlot package, all I've done is added a few new options to the placement of the labels.

        Here is an example from one of my applications. Most of the formatting options are set from the query string and can be modified at run-time.

        Of special note, the XTickLabel in this example is the numbering on the X-axis, whereas the XDataLabel appears at the point. In the regular PHPlot configuration you may only have one of these two. In my modification, both are allowed (since they aren't necessarily drawing at the same position). The new options for XDataLabel are listed here:

        http://www.agdconsulting.ca/webtools/phplot.php

        <?php

        require_once 'phplot.php';
        require_once 'config.inc.php'; // configuration stored elsewhere
        require_once /connect.inc.php'; // mySQL connect and usual functions
        require_once '/queries.inc.php'; // stores the canned queries for this project
        global $queries, $legend;

        $query=getqueries($_GET['query']); // query number specified by previous page
        $result = mysql_query($query) or die('Query failed: ' . mysql_error());

        $data = array();
        $minx=1e300;
        $maxx=-1e300;
        $miny=1e300;
        $maxy=-1e300;
        while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $data[]= $line;
        foreach (array_values($line) as $key => $i) {
        if (strcmp($key,'0')==0) { continue; } // skip empty
        if ($i==='') { continue; } // skip empty
        if (strcmp($key,'1')==0) {
        if (0+$i > $maxx) {$maxx=0+$i;}
        if (0+$i < $minx) {$minx=0+$i;}
        } else {
        if (0+$i > $maxy) {$maxy=0+$i;}
        if (0+$i < $miny) {$miny=0+$i;}
        }
        }
        }
        $minx= round(($minx<0)?$minx1.1:$minx.9, -log10($minx/5)); // sets the X axis minimum
        $maxx= round(($maxx>0)?$maxx1.1:$maxx.9, -log10($maxx/5)); // sets the X axis maximum
        $miny= round(($miny<0)?$miny1.1:$miny.9, -log10($miny/5)); // sets the Y axis minimum
        $maxy= round(($maxy>0)?$maxy1.1:$maxy.9, -log10($maxy/5)); // sets the Y axis maximum

        mysql_free_result($result);

        $plot = new PHPlot(1000, 500);
        $plot->SetImageBorderType('plain');

        // X axis config
        $plot->SetXLabelAngle(90);
        $plot->SetXTickLabelPos('xaxis');
        $plot->SetLabelAngle(0);
        if (isset($_GET['label'])) { $plot->SetXDataLabelPos($_GET['label']);} // sets where the label appears realative to the point

        $plot->SetPlotType('points');
        $plot->SetDataType('data-data');
        $plot->SetDataValues($data);
        $plot->SetDataColors( array('red','blue','black','peru','cyan','navy'));
        $plot->SetLineStyles( array('solid', 'dashed', 'dashed','solid','solid'));
        $plot->SetPointShapes( array('diamond','circle','cross','circle','triangle','dot'));
        $plot->SetPointSizes( array(5,5,5,3,4,3));
        $plot->SetDefaultDashedStyle('6-4');
        $plot->SetDrawBrokenLines(true);

        // Set data range and tick increments to get nice even numbers:
        $plot->SetPlotAreaWorld($minx, $miny, $maxx, $maxy);
        $plot->SetPlotBorderType('full');
        if (isset($_GET['legendx'])&(isset($_GET['legendy']))) { $plot->SetLegendPixels($_GET['legendx']+0,$_GET['legendy']+0);} // positions the legend, if necessary

        // Draw both grids:
        $plot->SetDrawXGrid(True);
        $plot->SetDrawYGrid(True);

        $keys=array_keys($data[1]);
        $moo=getfieldinfo($keys[1], "labels"); // comes from queries.php

        if (isset($moo))
        $keys[1]=getfieldinfo($keys[1],"labels"); // comes from queries.php
        $plot->SetXTitle( html_entity_decode(htmlentities($keys[1], ENT_QUOTES, "UTF-8") ), "plotdown");
        $plot->SetYTitle( html_entity_decode(htmlentities($keys[0], ENT_QUOTES, "UTF-8") ), "plotleft"); / html to encode symbols like &micro; /
        @array_shift($keys); @array_shift($keys); // get rid of the non-Y axis labels
        $plot->SetLegend( $keys);

        // Make the points bigger so we can see them:
        $plot->SetPointSizes(7);

        $plot->DrawGraph();
        / done /
        ?>

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.