An Example of a Google Bar Chart

by jhorvath

HTML

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  <div id="chart_div"></div>

JavaScript

google.charts.load('current', {
  packages: ['corechart', 'line']
});
google.charts.setOnLoadCallback(drawCurveTypes);

function drawCurveTypes() {
  var data = new google.visualization.DataTable();
  data.addColumn('number', 'X');
  data.addColumn('number', 'Bid');

  data.addRows(generatePrices());

  var options = {
    hAxis: {
      title: 'Time'
    },
    vAxis: {
      title: 'Popularity'
    },
    series: {
      1: {
        curveType: 'function'
      }
    }
  };

  var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
  chart.draw(data, options);
}

// Next price is determined by the following:
// Tick price: 
// 						jumps 1-4 times per second, 
//						1 jump is between 1-3 spread,
//						probabilty of direction: 50% +- trend modifier (sideway: 0%, bull/bear: +-2%)
// Minute price: adjust trend modifier
// 						the more the closing price is away from trend, the higher the trend modifier will be in opposite direction

function generatePrices() {
	var prices = [];

	for(var i = 0; i < 15; i++) {
  	var minutePrices = generateMinutePrices(150, 1.05);
    for(var j = 0; j < minutePrices.length; j++) {
    	prices.push([prices.length, minutePrices[j]]);
    }
  }

	return prices;
}

function generateSecondPrices(price, trendModifier) { // trendModifier is a percentage value, 100% i.e. 1.0 means no modification, 90% i.e. 0.9 means bearish, 150% means strong bullish 
	var tickPrices = [];
  var spreadPercentage = 0.0025; // i.e. 150 USD stock has 36 cent spread
  var oldPrice = price;
  
  var numberOfTicks = getRandomInt(1, 4);
  for(var i = 0; i < numberOfTicks; i++) {
  	var jumpDirection = getRandomInt(1,100) * trendModifier >= 50 ? 1 : -1; // i.e. up or down move
    var jumpSizeInSpreads = getRandomInt(1, 3);
    var spreadPrice = oldPrice * spreadPercentage;
    
    var priceChange = jumpDirection * jumpSizeInSpreads * spreadPrice;
    var newPrice = oldPrice + priceChange;
    oldPrice = newPrice;
    
   ...