goat1000 / SVGGraph

PHP SVG graph library
http://www.goat1000.com/svggraph.php
GNU Lesser General Public License v3.0
120 stars 30 forks source link

BarAndLineGraph line colour #57

Open e22c opened 2 years ago

e22c commented 2 years ago

How to change colour of the line - marker's colour is as desired, but line is always the same - black. I see the position of the line marker is always in the middle. Is it possible to fix it on middle of specific bar? If for example we have 5 bars and 1 line - line marker we want on bar 4? Is this possible?

Anyway great work.

goat1000 commented 2 years ago

The line colour on bar and line graphs comes from the colour functions - except when the stroke_colour option is set, then that is used instead.

For a graph with five bars and then a line dataset you could use this:

// black bar edges, red graph line
$settings['stroke_colour'] = ['#000', '#000', '#000', '#000', '#000', '#f00'];

or

// black bar edges, red-blue gradient graph line
$settings['stroke_colour'] = ['#000', '#000', '#000', '#000', '#000', ['#f00','#00f', 'h'];

There isn't a way to position the line markers over a specific bar at the moment - I'll add it to my list of things to work on for the next version.

goat1000 commented 2 years ago

Changeset 099078b89e25ea105b1a2b2be2e7db43846640fe adds a new option for positioning the line markers over bars, line_bar. The default is null to leave the marker in the middle of the group, or you can set a bar number to centre the markers over, or use an array to position multiple line datasets over different bars.