• I have tried exporting data to a .csv file and it works. If I try the exact same data by returning it as an array in the filter, as documented here How-can-I-populate-chart-series-and-data-dynamically, I get a blank chart.

    I am using

    add_filter( 'visualizer-get-chart-data', 'xyz_filter_hist_chart_data', 10, 3 );
    function xyz_filter_hist_chart_data( $data, $chart_id, $type ) {
        // do your stuff here
    	global $wpdb;
    	$sql = "SELECT date, store1, store2, store3, store4, store5 FROM wp_pricehist ORDER BY date ASC";
    
    //	$data = $wpdb->get_results( $sql, ARRAY_A );
    	$data = $wpdb->get_results( $sql, ARRAY_N );
    
        return $data;
    }

    https://www.ads-software.com/plugins/visualizer/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Yep, Works Great.
    You are missing one of the callbacks and you need to actually format the data arrays properly.

    Like Thus:

    function psm_filter_charts_data( $data, $chart_id, $type ) {
      global $current_user;
        get_currentuserinfo();
      	$Y = date("Y");
      	$Py = $Y-1;
      	$mssql = new db_mssql();
    
    	  $params = array(stripslashes($current_user->user_login),SQLSRV_PARAM_IN,SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),SQLSRV_SQLTYPE_VARCHAR('30'));
        $return = sqlsrv_query( $mssql->db, "{call SomeStoredProc(?)}", $params );
    
    	  if ( !$return )
    	    $this->html =  '<center><<Unable to retrieve survey data>></center>';
    	  else
    	  {
    	    if($record = sqlsrv_fetch_array($return)){
    	     $VG = round(($record['PYVeryGood']/$record['PYRegionVG'])*100);//Previous Year
    	  	 $VGYTD = round(($record['YTDVeryGood']/$record['YTDRegionVG'])*100);//Current Year To Date
    
    	  	 	$data = array(
    				    // the first row of data
    				    array(
    				        "$Y YTD", // the value of the first series
    				        $VGYTD
    				    ),
    				    // the second row of data
    				    array(
    				        "$Py", // the value of the first series
    				        $VG
    				    )
    				);
    
    	  	}
    	  }
    	  /*
    	  echo "Sample Sizes: <br /> $Y YTD: ".$record['YTDSampleSize']."<br />";
    	     echo "$Py: ".$record['PYSampleSize']."<br />";
    	  */
    	  $pqm = new Patient_Satisfaction_Metric();
    	  echo "<div id='pqmTable' style='display:none;'>"
    	       .$pqm->html.$pqm->css
    	       ."</div>";
    	  echo "
    	  <style>
    	    #visualizer-91{ cursor:pointer; }
    	  </style>
    	  <script>
    	  jQuery(document).ready( function() {
    	  jQuery('#visualizer-91').click(function(){location.href='/pp/patsat/'});
    	  jQuery('#visualizer-91').hover(function(){
    	    var title = jQuery('#pqmTable').html();
    	    jQuery(this).data('tipText', title).removeAttr('title');
    	    jQuery(\"<p class='tooltip'></p>\")
    	      .html(title)
    	      .appendTo('body')
    	      .fadeIn('slow');
    	    },function(){
    	      jQuery(this).attr('title', jQuery(this).data('tipText'));
            jQuery('.tooltip').remove();
    	    }).mousemove(function(e) {
                    var mousex = e.pageX + 20; //Get X coordinates
                    var mousey = e.pageY + 10; //Get Y coordinates
    
                    jQuery('.tooltip')
                    .css({ top: mousey,
                           left: mousex,
                           position: 'absolute',
                           background: '#EFF4F8',
                           border:'1px solid #004B73',
                           padding: '10px' })
    	    });
    	  });</script>";
        return $data;
    }
    add_filter( 'psm-get-chart-data', 'psm_filter_charts_data', 10, 3 );
    
    function psm_filter_charts_series( $series, $chart_id, $type ) {
    	     $series = array(
    				    // the first series
    				    array(
    				        'label' => 'Patient Satisfaction', // the label of the series
    				        'type' => 'string' // the type of the series
    				    ),
    				    // the second series
    				    array(
    				        'label' => 'Value', // the label of the series
    				        'type' => 'number' // the type of the series
    				    )
    				);
    
        return $series;
    }
    add_filter( 'psm-get-chart-series', 'psm_filter_charts_series', 10, 3 );
    
    ShortCode:
    [visualizer id="91" series="psm-get-chart-series" data="psm-get-chart-data"]

    hi tcclinics,

    Can you please help me, i have written the following code for dynamic update but the chart is not showing up.

    <?php

    function psm_filter_charts_data( $data, $chart_id, $type )
    {
    // Connect to MySQL
    $link = mysql_connect( ‘localhost’, ‘root’, ‘root’ );
    if ( !$link )
    {
    die( ‘Could not connect: ‘ . mysql_error() );
    }

    // Select the data base
    $db = mysql_select_db( ‘test’, $link );
    if ( !$db )
    {
    die ( ‘Error selecting database \’test\’ : ‘ . mysql_error() );
    }

    // Fetch the data
    $query = ” SELECT category, value1 FROM my_chart_data ORDER BY category ASC”;
    $result = mysql_query( $query );
    while ( $row = mysql_fetch_assoc( $result ))
    {
    $data = array(
    array(
    “Date”, // the value of the first series
    $row[‘category’]
    ),
    array(
    “Data”, // the value of the first series
    $row[‘value1’]
    ),
    );
    echo $row[‘category’];
    }

    return $data;
    }
    add_filter( ‘psm-get-chart-data’, ‘psm_filter_charts_data’, 10, 3 );

    function psm_filter_charts_series( $series, $chart_id, $type )
    {
    $series = array(
    // the first series
    array(
    ‘label’ => ‘Date’, // the label of the series
    ‘type’ => ‘date’ // the type of the series
    ),
    // the second series
    array(
    ‘label’ => ‘Index’, // the label of the series
    ‘type’ => ‘number’ // the type of the series
    )
    );

    return $series;
    }
    add_filter( ‘psm-get-chart-series’, ‘psm_filter_charts_series’, 10, 3 );

    ?>

    [visualizer id=”5″ series=”psm-get-chart-series” data=”psm-get-chart-data”]

    jeethghambole,

    When you retrieve data from MySQL, type are always strings. So you need to convert your data type for date and number.

    Hello
    I’m newbie in WordPress! So i don’t know where i should put these code? in .php file of plugin? OR in main index.php of my WordPress site?
    Is there any more steps than what you said?
    Also could you give me basic reference for these coding?
    I will appreciate your help.
    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Has anyone able to get a chart working from the database?’ is closed to new replies.