Search code examples
javascriptphpjquerycanvasrgraph

How to manage hight of canvas in RGraph Rose chart?


I am using RGraph library for my assessment site. It is working well but canvas height is creating an issue with the layout of graph.

See the image below, it results in a good output but gets cropped from the bottom and that's why the fourth category name is not being displayed.

enter image description here

My Rose Chart Script is as below.

<script>
var catnames = <?php print json_encode(array_keys($values));?>;
var results = <?php print json_encode(array_values($str_val));?>;
var tooltipval = <?php print json_encode(array_values($values));?>;
window.onload = function ()
{
    var canvas = document.getElementById("cvs");

    RGraph.Reset(canvas);

    canvas.width  = jQuery(window).width() * 0.6;
    canvas.height = jQuery(window).width() * 0.25;
    var text_size = Math.min(12, (jQuery(window).width() / 1000) * 10 );
    var linewidth = jQuery(window).width() > 500 ? 2 : 1;
        linewidth = jQuery(window).width() > 750 ? 3 : linewidth;

        var rose = new RGraph.Rose({
        id: 'cvs',
        data: results,
        options: {
            variant: 'stacked',
            labelsAxes: '',
            margin: 2.5,
            /* anglesStart: -(RGraph.HALFPI/2), */

            key:catnames,
            keyBackground:'#fff',
            keyColorShape: 'circle',
            strokestyle: 'rgba(0,0,0,0)',
             labels: catnames,
              tooltips: tooltipval,
              linewidth:linewidth,
            colorsSequential: true
        }
    }).implode();

};

In the script given above catnames is the array of categories those are displayed as labels in the graph.


Solution

  • The code itself produces a chart with the label present.

    You could try reducing the radius using the radius: configuration property and see if the label appears by using the radius configuration property:

    ... radius: 100, ...