Rank: Advanced Member
Groups: Administrators, DataVizJavaScript, jQueryChart, jQueryDV, MvcChart, Registered Joined: 1/3/2011(UTC) Posts: 483
Thanks: 0 times Was thanked: 87 time(s) in 87 post(s)
|
Currently we still don't fully support annotations. Here is an example how you can add a vertical line on mouse click: Code: <script type="text/javascript">
function addDays(date, value) { var newDate = new Date(date.getTime()); newDate.setDate(date.getDate() + value); return newDate; }
function round(d) { return Math.round(100 * d) / 100; }
var data1 = []; var data2 = [];
var yValue1 = 50; var yValue2 = 200;
var date = new Date(2010, 0, 1);
for (var i = 0; i < 200; i++) {
yValue1 += Math.random() * 10 - 5; data1.push([date, round(yValue1)]);
yValue2 += Math.random() * 10 - 5; data2.push([date, round(yValue2)]);
date = addDays(date, 1); }
$(document).ready(function () {
var background = { type: 'linearGradient', x0: 0, y0: 0, x1: 0, y1: 1, colorStops: [{ offset: 0, color: '#d2e6c9' }, { offset: 1, color: 'white' }] };
$('#jqChart').jqChart({ title: 'Chart Title', legend: { title: 'Legend' }, border: { strokeStyle: '#6ba851' }, background: background, tooltips: { type: 'shared' }, shadows: { enabled: true }, crosshairs: { enabled: true, hLine: false, vLine: { strokeStyle: '#cc0a0c' } }, axes: [ { type: 'dateTime', location: 'bottom', zoomEnabled: true, plotLines: [] } ], series: [ { title: 'Series 1', type: 'line', data: data1, markers: null }, { title: 'Series 2', type: 'line', data: data2, markers: null } ] });
var selectedDate = null;
$('#jqChart').bind('dataHighlighting', function (e, data) { if (data) { selectedDate = data[0].x; } else { selectedDate = null; } });
$('#jqChart').bind('mousedown', function (e, data) {
if (!selectedDate) { return; }
var axes = $('#jqChart').jqChart('option', 'axes'); axes[0].plotLines.push({ value: selectedDate, strokeStyle: 'red' });
$('#jqChart').jqChart('update'); }); }); </script> </head> <body> <div id="jqChart" style="width: 500px; height: 350px;"> </div> </body>
Best Regards, Dragan Matek jqChart Inc.
|