在inoERP中重叠两个Pie SVG图表

时间:2015-07-16 05:33:10

标签: php svg charts erp

我有两组数据 1.按需要之前收到的购买订单。 2.按日期后收到的采购订单。

目前我们正在使用inoERP饼图并排显示两个图表进行比较。

现在,我想将两个重叠的SVG图组合在一起。即左侧显示来自x< = - 3和右侧x> = 3的所有数据.3& 3之间的任何数据。 +3将处于重叠期。

enter image description here

我向他们的团队发送了一封邮件,但得到的答复是他们不会对Oracle / SAP中没有的功能进行任何免费定制。所以,我想知道是否有任何方法可以实现这一目标。

我查看了产品的代码,并使用下面的代码

private function _draw_pie() {
  if ((empty($this->_data)) || (!is_array($this->_data))) {
   return;
  }
  $x_cordinate = $this->_left_margin;
  $y_cordinate = $this->_top_margin;
  $this->_prepare_pie();
  $title_yaxis = 10;

  if ($this->_chart_width > $this->_chart_height) {
   $radius = ($this->_chart_height / 2);
  } else {
   $radius = ($this->_chart_width / 2);
  }
  $title_xaxis = $this->_left_margin + $radius;
  $cx = $x_cordinate + $radius;
  $cy = $y_cordinate + $radius;
  $sum_of_elements = array_sum($this->_data);
  if ($sum_of_elements <= 0) {
   echo "<br> Wrong data selection. No value in value field";
   return;
  }

  $legend_yaxis = $this->_top_margin;
  $legend_xaxis = $cx + $radius * 1.2;

  $chart = "<div class='chart_name'>" . $this->_chart_name . '</div>';
  if ($this->_chart_type != 'donut') {
   $pie_chart_height = 2.5 * $radius;
   $chart .= "<svg class='chart pie' width=\"$this->_chart_width_orginal\" height=\"{$pie_chart_height}\">";
  } else {
   $chart .= "<svg class='chart pie' width=\"$this->_chart_width_orginal\" height=\"$this->_chart_height_orginal\">";
  }
  $chart .= '<text x="' . $title_xaxis . '" y="' . $title_yaxis . '"     class="chart_xaxis_title" >' . $this->_x_axis_text . '   </text>';

  $last_x = $radius;
  $last_y = 0;
  $cum_val = $cum_segment = 0;
  $count = 0;
  $large_arc = 0;
  $chart .= "<g transform=\"translate(0,0)\">";

  foreach ($this->_data as $key => $value) {
   $cum_val += $value;
   $div_class = 'pie_element value cluster_class_' . $count;
   if ((($value / $sum_of_elements) * 360) > 180) {
    $large_arc = 1;
   } else {
    $large_arc = 0;
   }
   $cum_segment += ($value / $sum_of_elements) * 360;
   $last_y_m = -($last_y);
   $next_x = $radius * cos(deg2rad($cum_segment));
   $next_y = $radius * sin(deg2rad($cum_segment));
   $end_point_x = ($next_x - $last_x);
   $end_point_y = -($next_y - $last_y);
   $chart .= "<path id=\"pie_path_$count\" d=\"M$cx,$cy
                l$last_x, $last_y_m
              a$radius,$radius 0 $large_arc,0 $end_point_x,$end_point_y z \"
          style=\"stroke:#660000; \" class=\"$div_class\"/>";
   $last_x = $next_x;
   $last_y = $next_y;
   $count++;
  }
  $chart .= '</g>';
  $key_count = 0;
  foreach ($this->_data as $key => $value) {
   $cluster_class = 'pie_element cluster_class_' . $key_count;
   $legend_y_axis_rect = $legend_yaxis - 10;
   $chart .= "<rect x=\"$legend_xaxis\" y=\"$legend_y_axis_rect\" width=\"10\" height=\"10\" class=\" $key $cluster_class legend \"/>";
   $legend_xaxis += 15;
   $chart .= '<text x="' . $legend_xaxis . '" y="' . $legend_yaxis . '"  class="chart_pie_value " >' . round($value / $sum_of_elements * 100, 1) . '% </text>';
   $legend_xaxis += 45;
   if (strlen($key) > 15) {
    $legend_yaxis_os = 0;
    $legend_xaxis_os = 0;
    $key_a = explode(' ', $key);
    foreach ($key_a as $nl_k => $new_line) {
     $chart .= '<text x="' . $legend_xaxis . '" y="' . $legend_yaxis . '"  class="chart_legend_title" >' . $new_line . ' </text>';
     $legend_yaxis += 20;
     $legend_xaxis -= 60;
    }
    $legend_xaxis += 60;
   } else {
    $chart .= '<text x="' . $legend_xaxis . '" y="' . $legend_yaxis . '"  class="chart_legend_title" >' . $key . ' </text>';
    $legend_yaxis += 40;
    $legend_xaxis -= 60;
   }
   $key_count++;
  }
  $chart .= '<text x="' . $legend_xaxis . '" y="' . $legend_yaxis . '"  class="chart_pie_value" >   (Total : ' . $sum_of_elements . ')  </text>';
  if ($this->_chart_type != 'donut') {
   $chart .= '</svg>';
  }
  return $chart;
 }

1 个答案:

答案 0 :(得分:1)

我认为这可能会对您有所帮助。 关键字是VENN DIAGRAMS。

install.packages('VennDiagram')
library(VennDiagram)
grid.newpage()
draw.pairwise.venn(22, 20, 11, category = c("Dog", "Cat"), lty = rep("blank", 
    2), fill = c("light blue", "pink"), alpha = rep(0.5, 2), cat.pos = c(0, 
    0), cat.dist = rep(0.025, 2), scaled = FALSE)

Venn diagram here