JavaScript/jQuery: Manipulate number in chart tooltip

In this example, if you hover over a point on the chart, the value of x is displayed in a tooltip.  I want the value of x*2 to be displayed in the tooltip.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="http:////cdnjs.cloudflare.com/ajax/libs/flot/0.8.1/jquery.flot.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/krzysu/flot.tooltip/master/js/jquery.flot.tooltip.min.js"></script>
</head>
<body>
<div id="placeholder" style="width:600px;height:300px;"></div>
<script type="text/javascript">
var format = {
    grid: {
        show: true,
        aboveData: true,
        hoverable: true,
        autoHighlight: true,
        mouseActiveRadius: 20
    },
    series: {
        lines: {
            show: true,
        },
        points: {
            show: true
        }
    },
    xaxis: {
        show: true
    },
    yaxis: {
        show: true
    },
    tooltip: true,
    tooltipOpts: {
        content: "%x * 2 = ???",
        shifts: {
            x: -30,
            y: -50
        }
    }
};
$(document)
    .ready(function () {
        var d1 = [];
        for(var i = 0; i < 61; i++)
            d1.push([i, Math.sin(i)]);
        $.plot($('#placeholder'), [{
            label: "Example",
            data: d1,
    }], format);
});
</script>
</body>
</html>

Open in new window

LVL 16
hankknightAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott FellDeveloper & EE ModeratorCommented:
http://jsbin.com/EROJISan/1/edit?html,output
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>Flot Examples: Interactivity</title>
	<link href="http://www.flotcharts.org/flot/examples/examples.css" rel="stylesheet" type="text/css">
	<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../../excanvas.min.js"></script><![endif]-->
	<script language="javascript" type="text/javascript" src="http://www.flotcharts.org/flot/jquery.js"></script>
	<script language="javascript" type="text/javascript" src="http://www.flotcharts.org/flot/jquery.flot.js"></script>
	<script type="text/javascript">
$(function() {

		var sin = [],
			cos = [];

		for (var i = 0; i < 61; i += 0.5) {
			sin.push([i, Math.sin(i)]);
			
		}

		var plot = $.plot("#placeholder", [
			{ data: sin, label: "sin(x)"},
			{ data: cos, label: "cos(x)"}
		], {
			series: {
				lines: {
					show: true
				},
				points: {
					show: true
				}
			},
			grid: {
				hoverable: true,
				clickable: true
			},
			yaxis: {
				min: -1.2,
				max: 1.2
			}
		});

		$("<div id='tooltip'></div>").css({
			position: "absolute",
			display: "none",
			border: "1px solid #fdd",
			padding: "2px",
			"background-color": "#fee",
			opacity: 0.80
		}).appendTo("body");

		$("#placeholder").bind("plothover", function (event, pos, item) {

		

			
				if (item) {
					var x = item.datapoint[0].toFixed(2),
						y = item.datapoint[1].toFixed(2);

                  $("#tooltip").html(item.series.label + " of " + x + " = " + y+"<br>x times 2 = "+ x*2)
						.css({top: item.pageY+5, left: item.pageX+5})
						.fadeIn(200);
				} else {
					$("#tooltip").hide();
				}
			
		});

		$("#placeholder").bind("plotclick", function (event, pos, item) {
			if (item) {
				$("#clickdata").text(" - click point " + item.dataIndex + " in " + item.series.label);
				plot.highlight(item.series, item.datapoint);
			}
		});

		// Add the Flot version string to the footer

		
	});

	

	

	</script>
</head>
<body>
	<div id="header">
		<h2>Interactivity</h2>
	</div>

	<div id="content">

		<div class="demo-container">
			<div id="placeholder" class="demo-placeholder"></div>
		</div>
  </div> 

		

</body>
</html>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.