WYSIJA_help_charts

The MailPoet Newsletters WYSIJA help charts class.

Defined (1)

The class is defined in the following location(s).

/helpers/charts.php  
  1. class WYSIJA_help_charts extends WYSIJA_object { 
  2.  
  3. function __construct() { 
  4. parent::__construct(); 
  5.  
  6. function pieChart($id, $options = array()) { 
  7. return $this->generateChart('pie', $id, $options); 
  8.  
  9. function serialChart($id, $options = array()) { 
  10. return $this->generateChart('serial', $id, $options); 
  11.  
  12. function generateChart($type = 'serial', $id, $options = array()) { 
  13. // format id 
  14. $id = str_replace(' ', '-', $id); 
  15. // chart dimensions 
  16. $width = (isset($options['width'])) ? (int)$options['width'] : 400; 
  17. $height = (isset($options['height'])) ? (int)$options['height'] : 225; 
  18.  
  19. // chart title 
  20. $title = (isset($options['title'])) ? $options['title'] : null; 
  21.  
  22. // data 
  23. $data = (isset($options['data'])) ? $options['data'] : null; 
  24.  
  25. // generate JS code 
  26. $content = '<div id="wysija-chart-'.$id.'" class="wysija-chart" style="width:'.$width.'px;height:'.$height.'px;"></div>'; 
  27. $content .= '<script type="text/javascript">'; 
  28. $content .= 'AmCharts.ready(function () {'; 
  29. $content .= 'WysijaCharts.generateChart("'.$type.'", "wysija-chart-'.$id.'", {'; 
  30. // set chart title 
  31. $content .= 'title: "'.$title.'", '; 
  32. // set data 
  33. $content .= 'data: '.json_encode($data).', '; 
  34.  
  35. switch ($type) { 
  36. case 'serial': 
  37. // axes data 
  38. $axes = (isset($options['axes'])) ? $options['axes'] : null; 
  39. // category (the field used to sort by) 
  40. $category = (isset($options['category'])) ? $options['category'] : null; 
  41.  
  42. $content .= 'axes: '.json_encode($axes).', '; 
  43. $content .= 'category: "'.$category.'"'; 
  44. break; 
  45. case 'pie': 
  46. // title and value fields 
  47. $titleField = (isset($options['titleField'])) ? $options['titleField'] : null; 
  48. $valueField = (isset($options['valueField'])) ? $options['valueField'] : null; 
  49.  
  50. $content .= 'titleField: "'.$titleField.'", '; 
  51. $content .= 'valueField: "'.$valueField.'"'; 
  52.  
  53. break; 
  54.  
  55. $content .= '});'; 
  56. $content .= '});'; 
  57. $content .= '</script>'; 
  58. return $content;