Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9027823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:50:20+00:00 2026-06-16T06:50:20+00:00

I’m using FPDF in my php project. I would like to have PDF version

  • 0

Double bar diagram

I’m using FPDF in my php project. I would like to have PDF version Double bar diagram like above image in my project. There’s a way that FPDF can create Pie chart and Bar diagram in http://www.fpdf.org/en/script/script28.php. But it’s not double bar diagram like what I want to get. Anyone have an idea how to create Double bar diagram using FPDF in PHP?
Many Thanks !!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:50:22+00:00Added an answer on June 16, 2026 at 6:50 am

    Probably you mean “COLUMN CHARTS”

    It seems that there is no method to create column charts, so I tried to adapt the existing bar chart. Unfortunately I have no time to develop it further.

    try this (making the necessary changes):

    <?php
    
    require('diag/sector.php');
    
    class PDF_Diag extends PDF_Sector {
        var $legends;
        var $wLegend;
        var $sum;
        var $NbVal;
    
    
        function ColumnChart($w, $h, $data, $format, $color=null, $maxVal=0, $nbDiv=4)
        {
    
            // RGB for color 0
            $colors[0][0] = 155;
            $colors[0][1] = 75;
            $colors[0][2] = 155;
    
            // RGB for color 1
            $colors[1][0] = 0;
            $colors[1][1] = 155;
            $colors[1][2] = 0;
    
            // RGB for color 2
            $colors[2][0] = 75;
            $colors[2][1] = 155;
            $colors[2][2] = 255;
    
            // RGB for color 3
            $colors[3][0] = 75;
            $colors[3][1] = 0;
            $colors[3][2] = 155;
    
            $this->SetFont('Courier', '', 10);
            $this->SetLegends($data,$format);
    
            // Starting corner (current page position where the chart has been inserted)
            $XPage = $this->GetX();
            $YPage = $this->GetY();
            $margin = 2; 
    
            // Y position of the chart
            $YDiag = $YPage + $margin;
    
            // chart HEIGHT
            $hDiag = floor($h - $margin * 2);
    
            // X position of the chart
            $XDiag = $XPage + $margin;
    
            // chart LENGHT
            $lDiag = floor($w - $margin * 3 - $this->wLegend);
    
            if($color == null)
                $color=array(155,155,155);
            if ($maxVal == 0) 
            {
                foreach($data as $val)
                {
                    if(max($val) > $maxVal)
                    {
                        $maxVal = max($val);
                    }
                }
            }
    
            // define the distance between the visual reference lines (the lines which cross the chart's internal area and serve as visual reference for the column's heights)
            $valIndRepere = ceil($maxVal / $nbDiv);
    
            // adjust the maximum value to be plotted (recalculate through the newly calculated distance between the visual reference lines)
            $maxVal = $valIndRepere * $nbDiv;
    
            // define the distance between the visual reference lines (in milimeters)
            $hRepere = floor($hDiag / $nbDiv);
    
            // adjust the chart HEIGHT
            $hDiag = $hRepere * $nbDiv;
    
            // determine the height unit (milimiters/data unit)
            $unit = $hDiag / $maxVal;
    
            // determine the bar's thickness
            $lBar = floor($lDiag / ($this->NbVal + 1));
            $lDiag = $lBar * ($this->NbVal + 1);
            $eColumn = floor($lBar * 80 / 100);
    
            // draw the chart border
            $this->SetLineWidth(0.2);
            $this->Rect($XDiag, $YDiag, $lDiag, $hDiag);
    
            $this->SetFont('Courier', '', 10);
            $this->SetFillColor($color[0],$color[1],$color[2]);
            $i=0;
            foreach($data as $val) 
            {
                //Column
                $yval = $YDiag + $hDiag;
                $xval = $XDiag + ($i + 1) * $lBar - $eColumn/2;
                $lval = floor($eColumn/(count($val)));
                $j=0;
                foreach($val as $v)
                {
                    $hval = (int)($v * $unit);
                    $this->SetFillColor($colors[$j][0], $colors[$j][1], $colors[$j][2]);
                    $this->Rect($xval+($lval*$j), $yval, $lval, -$hval, 'DF');
                    $j++;
                }
    
                //Legend
                $this->SetXY($xval, $yval + $margin);
                $this->Cell($lval, 5, $this->legends[$i],0,0,'C');
                $i++;
            }
    
            //Scales
            for ($i = 0; $i <= $nbDiv; $i++) 
            {
                $ypos = $YDiag + $hRepere * $i;
                $this->Line($XDiag, $ypos, $XDiag + $lDiag, $ypos);
                $val = ($nbDiv - $i) * $valIndRepere;
                $ypos = $YDiag + $hRepere * $i;
                $xpos = $XDiag - $margin - $this->GetStringWidth($val);
                $this->Text($xpos, $ypos, $val);
            }
        }
    
        function SetLegends($data, $format)
        {
            $this->legends=array();
            $this->wLegend=0;
            $this->NbVal=count($data);
        }
    }
    
    
    $pdf = new PDF_Diag();
    $pdf->AddPage();
    
    
    $data[0] = array(470, 490, 90);
    $data[1] = array(450, 530, 110);
    $data[2] = array(420, 580, 100);
    
    
    // Column chart
    $pdf->SetFont('Arial', 'BIU', 12);
    $pdf->Cell(210, 5, 'Chart Title', 0, 1, 'C');
    $pdf->Ln(8);
    $valX = $pdf->GetX();
    $valY = $pdf->GetY();
    $pdf->ColumnChart(110, 100, $data, null, array(255,175,100));
    //$pdf->SetXY($valX, $valY);
    
    $pdf->Output();
    
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words
I have thousands of HTML files to process using Groovy/Java and I need to
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.