Menu

phplot doesn`t show x labels with multiple plots

Artem
2016-07-18
2016-07-30
  • Artem

    Artem - 2016-07-18

    Hello all.

    I found a strange thing, maybe it`s bug. I created two plots on the one image. First has type lines, second - bars. The issue is that x labels not appears to the bars plot. But if I delete first plot or change it type to bars - x labels for the second plot becomes visible.

    Code:

    <?php
    
        require_once('phplot-6.2.0/phplot.php');
    
        // First plot data
        $data1 = array(
            array('', 1468137200, 50),
            array('', 1468248200, 111),
            array('', 1468359200, 75),
            array('', 1468460200, 95),
            array('', 1468571200, 98),
        );
    
        // Second plot data
        $data2 = array(
            array('mar', 2),
            array('apr', 4),
            array('may', 6),
            array('jun', 10),
            array('jul', 12),
            array('aug', 14),
            array('sep', 20),
        );
    
        $plot_width = 500;
        $plot_height = 500;
        $plot_margin_top = 30;
        $plot_margin_bottom = 30;
    
        $plot = new PHPlot($plot_width, $plot_height);
        $plot->SetPrintImage(0);
    
        # Draw first plot
        $plot->SetPlotType('lines');
        $plot->SetDataType('data-data');
        $plot->SetXLabelType('time', '%d %b');
        $plot->SetNewPlotAreaPixels(null , 0 + $plot_margin_top,  null, $plot_height / 2 - $plot_margin_bottom);
        $plot->SetPlotAreaWorld(NULL, 0, NULL, NULL);
        $plot->SetDataValues($data1);
        $plot->DrawGraph();
    
        # Draw second plot
        $plot->SetPlotType('bars');
        $plot->SetDataType('text-data');
        $plot->SetXTickLabelPos('none');
        $plot->SetXTickPos('none');
        $plot->SetNewPlotAreaPixels(null, $plot_height / 2 + $plot_margin_top, null, $plot_height - $plot_margin_bottom);
        $plot->SetPlotAreaWorld(NULL, 0, NULL, NULL);
        $plot->SetDataValues($data2);
        $plot->DrawGraph();
    
        $plot->PrintImage();
    

    Two plots:

    Only second:

     

    Last edit: Artem 2016-07-18
  • Artem

    Artem - 2016-07-30

    I found solution. For the second plot I set x label type to default:

    $plot->SetXLabelType('');
    
     

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.