Line Chart with custom toolTip formatter- CanvasJS JavaScript Charts

Line Chart with custom toolTip formatter- CanvasJS JavaScript Charts

HTML

<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<br/><!-- Just so that JSFiddle's Result label doesn't overlap the Chart -->
<div id="chartContainer" style="height: 360px; width: 100%;"></div>

JavaScript

var chart = new CanvasJS.Chart("chartContainer",
	{
		title: {
			text: "Custom toolTip function "
		},
		toolTip: {			
			contentFormatter: contentFormatter
		},
    axisX: {
    	logarithmic: true
    },
		axisY: {
			includeZero: false
		},
    axisY2: {
			includeZero: false
		},
		data: [
		{
			type: "line",
			showInLegend: true,
			name: "Visits",
			dataPoints: [
				{ x: 1000, y: 650 },
				{ x: 10000, y: 700 },
				{ x: 100000, y: 710 },
				{ x: 1000000000, y: 658 },
				{ x: 1000000000000, y: 734 },
				{ x: 10000000000000, y: 963 },
				{ x: 1000000000000000, y: 847 }
			]
		},
    {
			type: "line",
			showInLegend: true,
			name: "Visits",
      axisYType: "secondary",     
			dataPoints: [
				{ x: 1000, y: 4500 },
				{ x: 10000, y: 3900 },
				{ x: 100000, y: 3210 },
				{ x: 1000000000, y: 3608 },
				{ x: 1000000000000, y: 3734 },
				{ x: 10000000000000, y: 2163 },
				{ x: 1000000000000000, y: 2247 }
			]
		},
		]
	});
	chart.render();
  
function contentFormatter(e){
  var hashrate = e.entries[0].dataPoint.x;
  if (hashrate < 1000000) {    
    return (Math.round(hashrate / 1000) / 1000 ).toFixed(2)+' Sol/s';
  }
  var byteUnits = [ ' Sol/s', ' KSol/s', ' MSol/s', ' GSol/s', ' TSol/s', ' PSol/s' ];
  var i = Math.floor((Math.log(hashrate/1000) / Math.log(1000)) - 1);
  hashrate = (hashrate/1000) / Math.pow(1000, i + 1);
  
  return hashrate.toFixed(2) + byteUnits[i];
}