Page 1 of 1

Line graph, bug with legend and only one series name?

Posted: Tue Feb 07, 2012 3:06 am
by 15961432
When I give my line a series name, the legend refuses to show the series name unless there are multiple series

For example:

With the following series title set,
$myline->setTitle("UTILITIES Actual");

The graph will not display the series under one title in the legend, but instead shows a legend entry for each point on the graph
Image

The only work-around for this is to draw a 'fake line' on top of one of the axes
$line_fake=new Line($c->getChart());
$line_fake->setTitle(" ");
$line_fake->setLabels($labels);
$line_fake->addArray($data_fake);
$line_fake->setColor(new Color(128,128,128));

Now, I get the desired result, except for the extra line that appears in the legend
Image

Is there any other way to do this?

I think that the natural behavior for legends should be to use the series title if it exists, otherwise do a point-by-point listing

Thanks

Re: Line graph, bug with legend and only one series name?

Posted: Wed Feb 08, 2012 12:27 pm
by yeray
Hi,

By default, the Legend's LegendStyle::$AUTO is used. This LegendStyle shows the values if only one series is visible and shows the series' names if more than one series are visible.
If you want to force the legend to show the series' names, event if there's only one series, you can use LegendStyle::$SERIES as follows:

Code: Select all

$chart1->getLegend()->setLegendStyle(LegendStyle::$SERIES);

Re: Line graph, bug with legend and only one series name?

Posted: Wed Feb 08, 2012 2:12 pm
by 15961432
Thank you

I had been looking for something like this command and couldn't find it