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 7914723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:12:44+00:00 2026-06-03T14:12:44+00:00

A little background I am attempting to migrate a project built with Symfony 1.2

  • 0

A little background

I am attempting to migrate a project built with Symfony 1.2 from one server to another. One of the functions of the project is to build a graph (originally done with JpGraph 2.3.5).

The graph does not display as intended without modifications to the code and am looking for some insight on what I might be overlooking. Images are linked due to not having enough points to post. Graph Image Gallery

The following graph is what is generated by the code block below

<?php
    public function Graph($section) {
        $report = $section->getReport();
        $this->crews = array();
        foreach ($section->getCrews() as $crew) {
            $this->crews[$crew->getId()] = $crew;
        };

        # get the data
        $nextDayValues = $section->getNextDayValues();
        $nextDayValueLabels = $section->getNextDayValueLabels();

        $max_y = max($nextDayValues) < 7 ? 7 : max($nextDayValues);
        $this->crew_order = array_keys($nextDayValues);
        $this->summary = $this->getSummary();
        $this->bar_count = count($this->crews) + count($this->summary);

        $left    = 200;
        $right   =  30;
        $top     =  60;
        $bottom  =  80;
        $width   = 640;
        $height  = $top + $bottom + ($this->bar_count * 30 );

        $x_unit = $this->bar_count / ($height - $top - $bottom);
        $y_unit = $max_y / ($width - $left - $right);

        $csim_targets = array();
        $csim_alts = array();
        $bar_data = array();
        $max_days = 0;

        foreach ($this->crew_order as $i => $crew_id) {
            $csim_targets[$i] = url_for('units/index?crew_id='.$crew_id);
            $csim_alts[$i] = sprintf("Units for %s",
              $this->crews[$crew_id]->getCrew());

            # figure out the maximum y value
            $nextDayUnitsList = $this->crews[$crew_id]->getNextDayUnitsList();
            $units_array[$crew_id] = $nextDayUnitsList;

            if (count($nextDayUnitsList) > $this->max_days) {
                $this->max_days = count($nextDayUnitsList);
            };
        };

        $bg_values = array_values($nextDayValues);
        foreach ($this->summary as $summary) {
            array_push ($bg_values, $summary['value']);
        };

        $bg_bar = new BarPlot($bg_values);
        $bg_bar->SetCSIMTargets($csim_targets, $csim_alts);
        $bg_bar->SetNoFill(true);

        $fg_bars = $this->getFgBars($units_array);
        $fg_bar = new AccBarPlot($fg_bars);
        $fg_bar->SetFillColor('black');

        # initialize the graph
        $graph = new Graph($width, $height, 'auto');
        $graph->SetScale('textlin', 0, $max_y, 0, $this->bar_count);
        $graph->Set90AndMargin($left, $right, $top, $bottom);
        $graph->SetMarginColor('white');
        $graph->SetFrame(false);

        $graph->Add($fg_bar);
        $graph->Add($bg_bar);

        # add text labels
        foreach ($this->crew_order as $i => $crew_id) {
            $label = $this->value_label(
                $nextDayValueLabels[$crew_id],
                $i, $nextDayValues[$crew_id],
                10 * $x_unit, 5 * $y_unit
            );
            $graph->AddText($label);
        };

        foreach ($this->summary as $i => $summary) {
            $label = $this->value_label(
                $summary['value'],
                $i, $summary['value'],
                10 * $x_unit, 5 * $y_unit
            );
            $graph->AddText($label);
        };

        # add title
        $graph->title->Set(sprintf("%s - %s", $report->getName(),
          $section->getName()));
        $graph->title->SetFont(FF_VERDANA,FS_BOLD, 12);
        $graph->title->SetMargin(10);

        # add subtitle
        $graph->subtitle->Set(date('d-M-Y g:ia'));
        $graph->subtitle->SetFont(FF_VERDANA,FS_BOLD, 8);

        # configure x-axis
        $graph->xaxis->SetFont(FF_VERDANA, FS_NORMAL, 8);
        $graph->xaxis->SetLabelAlign('right', 'center');
        $graph->xaxis->SetLabelFormatCallback(array($this, 'x_axis_label'));
        $graph->xaxis->scale->ticks->Set(1, 0);

        # configure y-axis
        $graph->yaxis->SetFont(FF_VERDANA, FS_NORMAL, 8);
        $graph->yaxis->SetLabelAlign('center', 'top');
        $graph->yaxis->SetLabelAngle(45);
        $graph->yaxis->SetLabelFormatCallback(array($this, 'y_axis_label'));
        $graph->yaxis->SetPos('max');
        $graph->yaxis->SetLabelSide(SIDE_RIGHT);
        $graph->yaxis->SetTickSide(SIDE_LEFT);

        if (max($nextDayValues) > 28) {
            $graph->yaxis->scale->ticks->Set(7, 1);
        } else {
            $graph->yaxis->scale->ticks->Set(1, 1);
        };

        # configure legend
        $graph->legend->SetAbsPos(5, $height - 5, "left", "bottom");
        $graph->legend->SetColumns(count($this->legend));
        $graph->legend->SetFillColor('white');
        $graph->legend->SetShadow(false);

        $graph->SetImgFormat('png');

        return $graph;
    }

    private function getFgBars($units_array) {
        # initialize fg_bar data
        $empty_crews = array_fill_keys(array_keys($this->crew_order),0);

        # add segment bars
        foreach ($this->summary as $summary) {
            $empty_crews[] = 0;
        };

        $empty_segment = array();
        foreach (array_keys($this->legend_colors) as $status) {
            $empty_segment[$status] = $empty_crews;
        };

        $segments = array();
        for ($day = 0; $day < $this->max_days; $day++) {
            foreach (array_keys($empty_segment) as $status) {
                $segment = $empty_segment;
                foreach ($this->crew_order as $i => $crew_id) {
                    $nextDayUnitsList = $units_array[$crew_id];
                    if ($day + 1 < count($nextDayUnitsList)) {
                        $units = $nextDayUnitsList[$day];
                        $units_status = $units->getNextDayStatus();
                        $segment[$units_status][$i] = 1;
                    } elseif ($day + 1 == count($nextDayUnitsList)) {
                        $units = $nextDayUnitsList[$day];
                        $units_status = $units->getNextDayStatus();
                        $avail = $units->getUsedRatio();
                        $segment[$units_status][$i] = $avail;
                    } elseif ($day + 1 > count($nextDayUnitsList)) {
                        $segment[$units_status][$i] = 0;
                    };
                };
            };

            foreach ($this->summary as $i => $summary) {
                $diff = $summary['value'] - $day;
                if ($diff >= 1) {
                    $segment['summary'][$i] = 1;
                } elseif ($diff >= 0) {
                    $segment['summary'][$i] = $diff;
                } else {
                    $segment['summary'][$i] = 0;
                }
            };
            $segments[$day] = $segment;
        };

        # create legend
        $fg_bars = array();
        foreach (array_keys($empty_segment) as $status) {
            $fg_bar = new BarPlot($empty_crews);
            $fg_bar->setFillColor($this->legend_colors[$status]);

            if ($status <> 'summary') {
                $fg_bar->SetLegend($this->legend[$status]);
            };
            $fg_bars[] = $fg_bar;
        };

        # add segments
        foreach ($segments as $day => $segment) {
            foreach (array_keys($empty_segment) as $status) {
                $fg_bar = new BarPlot($segment[$status]);
                $fg_bar->setColor($this->legend_colors[$status]);
                $fg_bar->setFillColor($this->legend_colors[$status]);
                $fg_bars[] = $fg_bar;
            };
        };
        return $fg_bars;
    }
?>

Now the same graph on the new server using JpGraph 2.3.5 or JpGraph 3.5.0b1

A few problems can be seen:

  1. Colours are not applied
  2. x/y coord are offset (margins?)
  3. scale is off
  4. scale ticks are also removed

I am aware that to correct the colour you place $graph->Add($x); before modifying the properties. As such I had to move the code within the getFgBars() into Graph().

Which is documented in the manual under /docs/chunkhtml/ch29s02.html

With revising the code I broke apart the FgBars into $fg_bars[] & $lg_bars[] being the foreground data (color) & Legend bar.

If I remove the legend bar, the graph is displayed as intended.

Question:

What would be causing the margin / scale to go wonkey when adding on a second AccBarPlot()?

Solution:

Remove default theme. $graph->graph_theme = null; will restore both colour & margins without requiring to rewrite any code.

    # initialize the graph
    $graph = new Graph($width, $height, 'auto');
    $graph->SetScale('textlin', 0, $max_y, 0, $this->bar_count);
    $graph->Set90AndMargin($left, $right, $top, $bottom);
    $graph->SetMarginColor('white');
    $graph->SetFrame(false);
    $graph->graph_theme = null;

  • 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-03T14:12:45+00:00Added an answer on June 3, 2026 at 2:12 pm

    Solution:

    Remove default theme. $graph->graph_theme = null; after initalizing Graph() will restore both colour & margins without requiring to rewrite any code.

        # initialize the graph
        $graph = new Graph($width, $height, 'auto');
        $graph->SetScale('textlin', 0, $max_y, 0, $this->bar_count);
        $graph->Set90AndMargin($left, $right, $top, $bottom);
        $graph->SetMarginColor('white');
        $graph->SetFrame(false);
        $graph->graph_theme = null;
    

    Resources:

    /docs/chunkhtml/ch29.html#id2619634 – The order of SetTheme() and changing settings
    /docs/chunkhtml/ch29s02.html – Changing the display settings of line/bar graphs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A little background: I'm working on a project converting a webapp in another scripting
A little background: I am loading a WPF UI from a database which is
A little background, because this might be kind of confusing: the project I'm working
Little background: Recently I upgraded SQL server management studio 2005 by applying the patch
A little background first - When I do apt-get install downloads from my company
For a little background: I am working on a project in C++ in which
A little background first. I've been tasked with encrypting files with a Powershell script
A little background first: I'm a designer/developer and decided to use subversion for a
A little background: I use PowerShell on windows xp at work and I set
A little background: I'm writing a small word based maze game starting with a

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.