简体   繁体   English

如何在Jquery中绘制半圆形饼图

[英]How to Plot a Half pie chart in Jquery

I have two form arrays, 我有两个表单数组

$expenditure = $_POST['expenditure'];
$revennue = $_POST['revenue'];

I have to use the values from these array and plot a Pie chart ,Like half of the pie chart will show the relation of expenditure and other half revenue 我必须使用这些数组中的值并绘制一个饼图,就像饼图的一半将显示支出与另一半收入的关系

I tried using Jqplot something like this 我尝试使用Jqplot这样的东西

$(document).ready(function(){
  var data = [
  <?php foreach($revenue as $key=> $val){ 
         $x = ($val/array_sum($revennue))*180;   
  ?>
    ['<?php echo "rev_".$key ?>', <?php echo $x ?>],
<?php }?>
 <?php foreach($expenditure as $key=> $val){ 
         $x = ($val/array_sum($expenditure))*180;   
  ?>
    ['<?php echo "exp_".$key ?>', <?php echo $x ?>],
<?php }?>
  ];
  var plot1 = jQuery.jqplot ('chart1', [data],
    {
      seriesDefaults: {
        // Make this a pie chart.
        renderer: jQuery.jqplot.PieRenderer,
        rendererOptions: {
          // Put data labels on the pie slices.
          // By default, labels show the percentage of the slice.
          showDataLabels: true
          this.startAngle = 180
        }
      },
      legend: { show:false, location: 'e' }
    }
  );
});

But its showing me wrong pie chart , 但是它向我显示了错误的饼图,

Can Any one let me know how I can fix this 任何人都可以让我知道如何解决此问题吗

Thanks in Advance 提前致谢

I made an attempt to draw Half Pie Chart. 我试图绘制半饼图。 I don't know if there's an easier way to do this. 我不知道是否有更简单的方法可以做到这一点。

With the help of some calculations and hacks, I managed to plot one. 在一些计算和技巧的帮助下,我设法绘制了一个。 A dummy-data , startAngle , shadowDepth , dataLabels , seriesColors , backgroundColor helped me achieve this. 一个虚拟的数据, startAngleshadowDepthdataLabelsseriesColorsbackgroundColor帮助我实现这一目标。 Here's the JSFiddle link for the same : jqPLot - Half Pie Chart 这是相同的JSFiddle链接: jqPLot-Half Pie Chart

NOTE: When you hover over the chart, you can see the dummy-slice. 注意:将鼠标悬停在图表上时,可以看到虚拟切片。 I think you can fix that with a little research. 我认为您可以通过一些研究来解决此问题。

Let me know if you need any help. 让我知道您是否需要任何帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM