Advertisement
Guest User

category pie graph

a guest
Mar 30th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.20 KB | None | 0 0
  1. <?php  
  2.  
  3. function myscripts ()  
  4. {
  5.   wp_deregister_script('jquery');  
  6.   wp_register_script( 'jquery',get_bloginfo('wpurl') . "/wp-content/plugins/infograph/jquery-1.9.1.min.js");  
  7.   wp_enqueue_script('jquery');
  8.  
  9.   wp_register_script( 'jqplot',get_bloginfo('wpurl') . '/wp-content/plugins/infograph/src/jquery.jqplot.js', 'jquery');
  10. //  wp_enqueue_script( 'jqplot' ); // Not required as wp_enqueue_scripts below will invoke this.
  11.  
  12.   wp_register_script( 'bar', get_bloginfo('wpurl') . '/wp-content/plugins/infograph/src/plugins/jqplot.barRenderer.js', 'jqplot');
  13.   wp_enqueue_script( 'bar' );
  14.  
  15.   wp_register_script( 'cax', get_bloginfo('wpurl') . '/wp-content/plugins/infograph/src/plugins/jqplot.categoryAxisRenderer.js', 'jqplot');
  16.   wp_enqueue_script( 'cax' );
  17.  
  18.   wp_register_script( 'pol', get_bloginfo('wpurl') . '/wp-content/plugins/infograph/src/plugins/jqplot.pointLabels.js', 'jqplot');
  19.   wp_enqueue_script( 'pol' );
  20.  
  21.   wp_register_script( 'fun', get_bloginfo('wpurl') . '/wp-content/plugins/infograph/src/plugins/jqplot.funnelRenderer.js', 'jqplot');
  22.   wp_enqueue_script( 'fun' );
  23.  
  24.   wp_register_script( 'pie', get_bloginfo('wpurl') . '/wp-content/plugins/infograph/src/plugins/jqplot.pieRenderer.js', 'jqplot');
  25.   wp_enqueue_script( 'pie' );
  26.   wp_register_script( 'meg', get_bloginfo('wpurl') . '/wp-content/plugins/infograph/src/plugins/jqplot.meterGaugeRenderer.js', 'jqplot');
  27.   wp_enqueue_script( 'meg' );
  28. }
  29.  
  30. function add_css () {
  31.   wp_register_style('jqPlotStyleSheet', plugins_url() . '/infograph/src/jquery.jqplot.css');
  32.   wp_enqueue_style( 'jqPlotStyleSheet');
  33.   wp_register_style('InfographExamplesStyleSheet', plugins_url() . '/infograph/examples.css');
  34.   wp_enqueue_style( 'InfographExamplesStyleSheet');
  35. }
  36.  
  37. add_action('wp_enqueue_scripts', 'myscripts');
  38. add_action('wp_print_styles', 'add_css');  // See note at http://codex.wordpress.org/Function_Reference/wp_register_style
  39.  
  40. add_action( 'add_meta_boxes', 'category_meta_box_add' );  
  41.  
  42. function category_meta_box_add()  
  43. {  
  44.     add_meta_box( 'my-meta-box-id', 'Category by Percentage', 'categories', 'post', 'normal', 'high' );  
  45. }  
  46.  
  47. function categories($atts,$content = '') {
  48. $ch_cats = get_categories(array('orderby'=>'count','order'=>'desc') );
  49. $sayy= count($ch_cats);
  50. $chl='';
  51. for ($i=1;$i<=5;$i++)
  52.   {
  53.     $chl=$chl.'[\''.$ch_cats[$i-1]->name.'\','.$ch_cats[$i-1]->count.'],';  //[[[\'a\',25],[\'b\',14],[\'c\',7]]]
  54.      }
  55.  
  56. $chl='[['.substr($chl,0,-1).']]';  
  57.  
  58. return '<script>
  59. $(document).ready(function(){
  60. plot1 = $.jqplot(\'chart1\', '.$chl.', {
  61. title: \'Most popular categories of example.com\',
  62. seriesDefaults:{renderer:$.jqplot.PieRenderer,rendererOptions: { padding: 8, showDataLabels: true}},legend:{show:true,placement: \'outside\',rendererOptions: {numberRows: 1}},
  63. legend:{show:true,
  64.        placement: \'outside\',
  65.        rendererOptions: {
  66.        numberRows: 1
  67.                     },
  68.        location:\'s\',
  69.        marginTop: \'15px\'
  70.                  }      
  71.  });
  72. });
  73.  </script>
  74.  <div id="chart1" style="margin-top:30px;margin-bottom:30px; margin-left:20px; width:500px; height:300px;"></div>  ';
  75.  }
  76. add_shortcode('mycategories', 'categories');
  77. echo do_shortcode('[mycategories]');
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement