2.. You'll need a connection file to your database. I know everyone is a big fan of jumping on anyone not using mysqli, Tell it to GoDaddy. Some of us just dont have our own servers and the ability get them up to speed.
For now, I have to use the options available to me.....and I'll be dealing with GoDaddy in court. so....with mysqli not an option for me at the moment, ....
<?php
$hostname = "yourdatabasehost";
$username = "yourusername";
$dbname = "thedbname";
$password = "yourdatabasepassword";
mysql_connect($hostname, $username, $password) OR DIE ("Unable to
connect to database! Please try again later.");
mysql_select_db($dbname);
3. Save the above using any blank text editor such as word or notepad and save it as "connect.php", Upload or place the 'connect.php' file to a folder in your root directory. I named mine "functions".
4.. Get the data, ..adapt the following according to whatever database columns you might have or wish to chart , The Mysql date format is rendered as YYYY-MM-DD and that's a problem due to the "dashes" - the date needs to be modified from mysql's output format to JSON's preferred input format. The extraction process below solves this if you are querying dates from a mysql database using a single 'Ymd' formatted column as I am, and you do not have seperated columns for year, month, and day. If you have such, you may query them directly.
<?php
include("connect.php");
$query = $_POST['query'];
$query = strtoupper($query);
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$180mdate = date("Ymd", strtotime("-180 days"));
$SQL="SELECT EXTRACT( YEAR FROM `date`) AS 'year',
EXTRACT( MONTH FROM `date`) AS 'month',
EXTRACT( DAY FROM `date`) AS 'day',
`close`,
`alertcode`,
`shortvolumealerts`
FROM `yourtableName`
WHERE `symbol` = '$query'
AND `date` > '$180mdate'
ORDER BY `date` ASC";
$table = array();
$table['cols'] = array(
array('label' => 'Date', 'type' => 'date', 'role' => 'domain'),
array('label' => 'Close', 'type' => 'number', 'role' => 'data'),
array('label' => '', 'type' =>'string', 'role' => 'annotation' ),
array('label' => '', 'type' =>'string', 'role' => 'annotationText')
);
$table['rows'] = $rows;
$res = mysql_query($SQL);
while($r = mysql_fetch_assoc($res)) {
$temp = array();
$r['date'] = array($r['year'], $r['month']-1, $r['day']);
$r['date'] = implode(",", $r[('date')]);
$temp[] = array('v' =>"Date(".$r['date'].")");
$temp[] = array('v' => (float) $r['close']);
$temp[] = array('v' => $r['alertcode']);
$temp[] = array('v' => $r['shortvolumealerts']);
$rows[] = array('c' => $temp);
};
$table['rows'] = $rows;
$annotchart = json_encode($table);
?>
5.. copy the above as modified to a blank text document with word or notepad, etc, and save it as a .php file;
example: 'annotchart.php',
........then upload it to the 'functions' folder in your root directory.
6. Go to your header file: /wp-content/themes/theme_name/header.php
(child themes are suggested and there are wordpress plugins that build child themes that work well so no future updates will wipe out the code being added.)
7. You'll see a lot of stuff like this:
<!DOCTYPE html><!--[if lt IE 7]><html class="ie ie6 lte9 lte8 lte7" <?php language_attributes(); ?>><![endif]-->
<!--[if IE 7]><html class="ie ie7 lte9 lte8 lte7" <?php language_attributes(); ?>><![endif]-->
<!--[if IE 8]><html class="ie ie8 lte9 lte8" <?php language_attributes(); ?>><![endif]-->
<!--[if IE 9]><html class="ie ie9" <?php language_attributes(); ?>> <![endif]-->
<!--[if gt IE 9]> <html <?php language_attributes(); ?>> ![endif]-->
<!--[if !IE]><html <?php language_attributes(); ?>><![endif]-->
<head>
8. place immediately after the <head> tag, the following:
9. Then you will have something that looks a lot like this:
<!DOCTYPE html><!--[if lt IE 7]><html class="ie ie6 lte9 lte8 lte7" <?php language_attributes(); ?>><![endif]-->
<!--[if IE 7]><html class="ie ie7 lte9 lte8 lte7" <?php language_attributes(); ?>><![endif]-->
<!--[if IE 8]><html class="ie ie8 lte9 lte8" <?php language_attributes(); ?>><![endif]-->
<!--[if IE 9]><html class="ie ie9" <?php language_attributes(); ?>> <![endif]-->
<!--[if gt IE 9]> <html <?php language_attributes(); ?>> ![endif]-->
<!--[if !IE]><html <?php language_attributes(); ?>><![endif]-->
<head>
<title><?php wp_title(''); ?></title>
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width" />
10. Here you call your data using the php function we created by adding in the following: (notice there is no visible db connection file or code here for hackers... ) and add the google chart script to create the chart...
<?php include("functions/annotchart.php"); ?>
<script type="text/javascript">
google.load("visualization", "1.1", {"packages":["annotationchart"]});
google.setOnLoadCallback(drawChart18);
function drawChart18) {
var data = new google.visualization.DataTable(<?=$annotchart?>);
var options = {
title: "<?=$query?>: Short Volume Alert Price Chart",
height: 400,
displayAnnotations: true,
displayAnnotationsFilter: true
};
var chart18 = new google.visualization.AnnotationChart(document.getElementById("prvoalertchart_div"));
chart.draw(data, options);
};
</script>
11. Create a wordpress result / return page and insert: