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

Display 0 values and labels #16

Open mixahlos opened 6 years ago

mixahlos commented 6 years ago

Is it possible to display the zero values and their labels in the radar graph ? Right now, when I set a value to "0" is totally hidden in the graph.

Thank you

goat1000 commented 6 years ago

Zero values (and their labels) should be drawn on radar graphs, so if they are not appearing at all you might have found a bug.

Unless you have negative values the zeroes will all be in the centre of the graph so they will not be easy to see. Try setting the axis_min_v option to a negative number to move 0 away from the centre and see if the zero values show up.

mixahlos commented 6 years ago

I am sorry for the delay @goat1000

No the label or value is not displayed at all For example when I set Almond from 0.6 to 0 and see the page source :

Almond : 0.6 var tooltipOn='', initfns=['ttEvt'], tips={e5:'Fruity, 4.2',e6:'Almond, 0.6',e7:'Herbs, 3.1',e8:'Artichoke, 0.6',e9:'Pungent, 3.2',ea:'Fresh cut grass, 3.5',eb:'Bitter, 3.2',ec:'Radicchio, 0.6',ed:'Tomato Leaves, 3',ee:'Fresh apple, 0.6'}; Almond : 0 var tooltipOn='', initfns=['ttEvt'], tips={e5:'Fruity, 4.2',e6:'Herbs, 3.1',e7:'Artichoke, 0.6',e8:'Pungent, 3.2',e9:'Fresh cut grass, 3.5',ea:'Bitter, 3.2',eb:'Radicchio, 0.6',ec:'Tomato Leaves, 3',ed:'Fresh apple, 0.6'};

goat1000 commented 6 years ago

So you mean it is the tooltip that is not displaying? Not data labels?

Both are working here on a test page I made by copying your values, so you must be doing something differently. Could you send me an example script that shows it not working?

Thanks.

mixahlos commented 6 years ago

No, my mistake because I do not know how to find it and show to you the labels. Now I found them, but not the values... Here are the labels :

    <text x="150" y="37.9" text-anchor="middle">Fruity</text>
    <text x="231.79" y="103.32" text-anchor="start">Almond</text>
    <text x="200.55" y="211.48" text-anchor="start">Herbs</text>
    <text x="99.45" y="211.48" text-anchor="end">Artichoke</text>
    <text x="68.209" y="103.32" text-anchor="end">Pungent</text>

and here when I set Almond, Herbs to 0

    <text x="151.5" y="2.4" text-anchor="middle">Fruity</text>
    <text x="258.02" y="204.9" text-anchor="start">Artichoke</text>
    <text x="44.979" y="204.9" text-anchor="end">Pungent</text>

I am sorry, I don't know how can I show you better.

Thank you so much though

goat1000 commented 6 years ago

OK, it looks like both the data labels and the tooltips are not showing.

Is it possible for you to send me a copy of the script you are using? Without seeing your settings and data I can't tell where things are going wrong. Send it to my email address if you don't want to post it on GitHub - my email address is in any of the source files under the license notice.

mixahlos commented 6 years ago

Hi, I am sorry again for the delay. I Read all the values from the databas, So I don't know if this helps. I hope this is what you asked :)

Thank you again !

            foreach ($this->graphFields as $field) {
                $radarAr[$field->title] = (float) $field->value;
            }
            if (!empty($radarAr)) {
              require_once '../SVGGraph/SVGGraph.php';
              $settings = array(
                  'back_colour' => 'transparent', 'stroke_colour' => 'rgba(142, 146, 67, 0.8)',
                  'back_stroke_width' => 0, 'back_stroke_colour' => '#eee',
                  'axis_colour' => '#000', 'axis_overlap' => 5,
                  'grid_colour' => '#c9c9c9', 'label_colour' => '#3d492a',
                  'pad_top' => 0, 'pad_left' => 10, 'pad_bottom' => -20,
                  'link_base' => '/', 'link_target' => '_top',
                  'fill_under' => true, 'fill_opacity' => 0.6,
                  'marker_colour' => '#2b2b2a', 'auto_fit' => false,
                  'marker_size' => 3, 'show_x_axis' => false,
                  'grid_straight' => true, 'start_angle' => 90,
                  'marker_type' => array('x', 'cross'), 'reverse' => true
              );
              $graph = new SVGGraph(300, 250, $settings);
              $graph->Values($radarAr);
              $graph->colours = array('#8e9243', '#3d492a');
              $graph->Render('RadarGraph');
            }
goat1000 commented 6 years ago

I've tried your settings with some data I put together from the values you posted a week ago - and it is still working.

The only thing I can think of that would cause this is if the value is NULL instead of 0 (but your casting the value to float should make this impossible).

I've attached the test script I made and its output SVG file in a zip file - would you mind trying the script out and seeing if it produces the correct output, or if the 0 value is missing.

Thanks.

radar_zeroes.zip

kimbami commented 5 years ago

The file worked, with a couple of changes: $graph = new Goat1000\SVGGraph\SVGGraph(300, 250, $settings); $graph->colours(array('#8e9243', '#3d492a'));

However, try setting all values to zero and an error shows: Zero length axis (min >= max).

How can you show a chart with data sets that are zero?

goat1000 commented 5 years ago

To show a graph with all zero values you have to tell SVGGraph how long to draw the Y axis with the axis_max_v option. Set it to the value that makes the most sense for your application.

I realise this is not very user-friendly, so I'll see if I can make it use a default value in the next version.