添加图例到圆环图 - jqPlot

Dr.*_*eon 1 javascript jquery charts jqplot donut-chart

好的,这应该相对简单:

在此输入图像描述

  • 我正在添加一个圆环图,它确实有效
  • 但是,"图例"(Head (+)与相应的颜色一起)不会显示.

代码:

$(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' }
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Ani*_*air 5

KAMELEON,

看起来你犯了一个愚蠢的错误.:)

首先结束seriesDefaults属性,然后定义图例.

您已将图例放在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' }
    });
});
Run Code Online (Sandbox Code Playgroud)

我没有测试过.但我认为它应该有效.

谢谢.