1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
<script type='text/javascript' src='http://code.jquery.com/jquery-1.6.2.js'></script> <script type='text/javascript' src="http://elycharts.com/sites/elycharts.com/repo/lib/raphael.js"></script> <script type='text/javascript' src="http://elycharts.com/sites/elycharts.com/repo/dist/elycharts.min.js"></script> <style type='text/css'> /* style up the tooltips content */ .charlab { font-face: helvetica, arial; color: black; margin: 0; } .date { font-size: 10px; font-weight: normal } .visits { color: #5Af; font-weight: normal } .hits { color: #F80; font-weight: normal } .label { font-size: 12px; line-height: 14px; margin-left: 2px; font-weight: bold } </style> <script > $(function() { // let's loop to build tooltips and x labels. var thelabels = new Array(30); for (var i = 0; i < thelabels.length; i++) { thelabels[i] = (i % 6 === 0) ? (i + 1) + " september" : ""; } // build the chart using the "google analytics" template. $("#chart").chart({ template: "google_analytics", labels: thelabels, values: values() }); // start a loop that sets new data in the chart every 5 seconds. loop(); }); /* Here is a simple update function generating new random data for the plot */ function values() { var thevalues = new Array(31); var thevalues2 = new Array(31); for (var i = 0; i < thevalues.length; i++) { thevalues[i] = Math.floor(Math.random() * (i > 0 ? thevalues[i - 1] * 1.5 + 10 : 100) + 10); thevalues2[i] = Math.floor(Math.random() * (i > 0 ? thevalues2[i - 1] * 1.5 + 100 : 1000) + 100); } /* Note how we simply call again .chart with only the updated values */ return { serie1: thevalues, serie2: thevalues2 }; } function loop() { $("#chart").chart({ values: values() }); setTimeout('loop()', 5000); } // this is a reausable template definition. $.elycharts.templates['google_analytics'] = { type: "line", margins: [10, 15, 25, 15], /* Define how to draw tooltips starting from series data */ /* this can be an array with the tooltips content or a function to generate them on the fly */ tooltips: function(env, serie, index, value, label) { return "<div class='label'><p class='date'>September " + index + "</p><p><span class='visits'>Visits:</span> " + env.opt.values['serie1'][index] + "</p><p><span class='hits'>Hits:</span> " + env.opt.values['serie2'][index] + "</p></div>"; }, defaultSeries: { plotProps: { "stroke-width": 4 }, dot: true, rounded: false, dotProps: { stroke: "white", size: 5, "stroke-width": 1, opacity: 0 // dots invisible until we hover it }, startAnimation: { // use an animation to start plotting the chart active: true, type: "avg", // start from the average line. speed: 10000, // animate in 1 second. delay: 0, easing: ">" }, stepAnimation: { // defines an animation for data updates active: true, speed: 2000, delay: 0, easing: '<>' }, highlight: { scaleSpeed: 0, // do not animate the dot scaling. instant grow. scaleEasing: '', scale: 1.2, // enlarge the dot on hover newProps: { opacity: 1 // show dots on hover } }, tooltip: { height: 45, width: 80, padding: [3, 3], offset: [-15, -10], frameProps: { opacity: 0.95, /* fill: "white", */ stroke: "#000" } } }, series: { serie1: { fill: true, fillProps: { opacity: .1 }, color: "#26B", }, serie2: { axis: 'r', color: "#F80", plotProps: { "stroke-width": 2 }, dotProps: { stroke: "white", size: 3, "stroke-width": 1 } } }, defaultAxis: { labels: true, labelsProps: { fill: "#49B", "font-size": "10px" }, labelsAnchor: "start", labelsMargin: 5, labelsDistance: -8 }, axis: { l: { // left axis labels: true, labelsDistance: 0, labelsSkip: 1, labelsAnchor: "start", labelsMargin: 15, labelsProps: { fill: "#AAA", "font-size": "11px", "font-weight": "bold" } }, r: { // left axis labels: true, labelsDistance: 0, labelsSkip: 1, labelsAnchor: "end", labelsMargin: 15, labelsProps: { fill: "#AAA", "font-size": "11px", "font-weight": "bold" } } }, features: { mousearea: { type: 'axis' }, tooltip: { positionHandler: function(env, tooltipConf, mouseAreaData, suggestedX, suggestedY) { return [mouseAreaData.event.pageX, mouseAreaData.event.pageY, true] } }, grid: { draw: true, // draw both x and y grids forceBorder: [true, false, true, false], // force grid for external border ny: 2, // use 10 divisions for y grid nx: 5, // 10 divisions for x grid props: { stroke: "#CCC" // color for the grid } } } } //]]> </script> <!-- the div where we are going to plot --> <div id="chart" style="width: 100%; height: 200px"></div> |
Latest Snippets
- Firefox 133 Toolbars – Tabs on Bottom – Update Nov 24 29th November 2024
- Exclude category from blog while adding them to sitemap.xml 16th January 2024
- What Router can I use with Onestream Broadband? 28th June 2023
- Disable buying – Woocommerce 25th April 2023
- Windows Desktop Wallpaper Background for OCD users with shelves 13th April 2023
- Featured Image Admin Thumb – Working Plugin (WordPress 6.2) 6th April 2023
- Create a gallery in a Posts page 3rd March 2023
- Clickable elements too close together – Solved 21st February 2023
- Best ChatGPT Prompts 24th January 2023
- Make Elementor Accordion Closed by Default 13th January 2023
LINKS