Add Legend to Donut Chart - jqPlot

最后都变了- 提交于 2020-01-06 03:13:07

问题


OK, this should be relatively simple :

  • I'm adding a donut chart, which does work
  • However, the 'legend' (like Head (+) along with the corresponding colour) does NOT show up.

Code :

$(document).ready(function(){
  var s1 = [['Head (+)',<?php echo $headScore; ?>], ['Head (-)',<?php echo 6-$headScore; ?>]];
  var s2 = [['Body (+)',<?php echo $totalScore-$headScore; ?>], ['Body (-)',<?php echo 7-$totalScore+$headScore; ?>]];

  var plot3 = $.jqplot('linkchart', [s1,s2], {
      title:"Score Profile",
    seriesDefaults: {
      // make this a donut chart.
      renderer:$.jqplot.DonutRenderer,
      rendererOptions:{
        // Donut's can be cut into slices like pies.
        sliceMargin: 3,
        // Pies and donuts can start at any arbitrary angle.
        startAngle: -90,
        showDataLabels: false
      },
      legend: { show:true, location: 'e' }
    }
  });
});

What am I doing wrong?


回答1:


Kameleon,

It looks like you have done a silly mistake. : )

First end the seriesDefaults property and then define the legend.

You have placed the legend inside the seriesDefaults.

var plot3 = $.jqplot('linkchart', [s1,s2], {
    title:"Score Profile",
        seriesDefaults: {
            // make this a donut chart.
            renderer:$.jqplot.DonutRenderer,
            rendererOptions:{
                // Donut's can be cut into slices like pies.
                sliceMargin: 3,
                // Pies and donuts can start at any arbitrary angle.
                startAngle: -90,
                showDataLabels: false
            } // Not here...
        },
        //Place the legend here....
        legend: { show:true, location: 'e' }
    });
});

I have not tested it. But I think it should work.

Thank you.



来源:https://stackoverflow.com/questions/12130130/add-legend-to-donut-chart-jqplot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!