index.htm 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>Highcharts Example</title>
  7. <style type="text/css">
  8. #container {
  9. min-width: 300px;
  10. max-width: 1000px;
  11. height: 420px;
  12. margin: 1em auto;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  18. <script src="../../code/highstock.js"></script>
  19. <script src="../../code/modules/exporting.js"></script>
  20. <div id="container"></div>
  21. <script type="text/javascript">
  22. /**
  23. * This is an advanced demo of setting up Highcharts with the flags feature borrowed from Highstock.
  24. * It also shows custom graphics drawn in the chart area on chart load.
  25. */
  26. /**
  27. * Fires on chart load, called from the chart.events.load option.
  28. */
  29. function onChartLoad() {
  30. var centerX = 140,
  31. centerY = 110,
  32. path = [],
  33. angle,
  34. radius,
  35. badgeColor = Highcharts.Color(Highcharts.getOptions().colors[0]).brighten(-0.2).get(),
  36. spike,
  37. empImage,
  38. big5,
  39. label,
  40. left,
  41. right,
  42. years,
  43. renderer;
  44. if (this.chartWidth < 530) {
  45. return;
  46. }
  47. // Draw the spiked disc
  48. for (angle = 0; angle < 2 * Math.PI; angle += Math.PI / 24) {
  49. radius = spike ? 80 : 70;
  50. path.push(
  51. 'L',
  52. centerX + radius * Math.cos(angle),
  53. centerY + radius * Math.sin(angle)
  54. );
  55. spike = !spike;
  56. }
  57. path[0] = 'M';
  58. path.push('z');
  59. this.renderer.path(path)
  60. .attr({
  61. fill: badgeColor,
  62. zIndex: 6
  63. })
  64. .add();
  65. // Employee image overlay
  66. empImage = this.renderer.path(path)
  67. .attr({
  68. zIndex: 7,
  69. opacity: 0,
  70. stroke: badgeColor,
  71. 'stroke-width': 1
  72. })
  73. .add();
  74. // Big 5
  75. big5 = this.renderer.text('5')
  76. .attr({
  77. zIndex: 6
  78. })
  79. .css({
  80. color: 'white',
  81. fontSize: '100px',
  82. fontStyle: 'italic',
  83. fontFamily: '\'Brush Script MT\', sans-serif'
  84. })
  85. .add();
  86. big5.attr({
  87. x: centerX - big5.getBBox().width / 2,
  88. y: centerY + 14
  89. });
  90. // Draw the label
  91. label = this.renderer.text('Highcharts Anniversary')
  92. .attr({
  93. zIndex: 6
  94. })
  95. .css({
  96. color: '#FFFFFF'
  97. })
  98. .add();
  99. left = centerX - label.getBBox().width / 2;
  100. right = centerX + label.getBBox().width / 2;
  101. label.attr({
  102. x: left,
  103. y: centerY + 44
  104. });
  105. // The band
  106. left = centerX - 90;
  107. right = centerX + 90;
  108. this.renderer
  109. .path([
  110. 'M', left, centerY + 30,
  111. 'L', right, centerY + 30,
  112. right, centerY + 50,
  113. left, centerY + 50,
  114. 'z',
  115. 'M', left, centerY + 40,
  116. 'L', left - 20, centerY + 40,
  117. left - 10, centerY + 50,
  118. left - 20, centerY + 60,
  119. left + 10, centerY + 60,
  120. left, centerY + 50,
  121. left + 10, centerY + 60,
  122. left + 10, centerY + 50,
  123. left, centerY + 50,
  124. 'z',
  125. 'M', right, centerY + 40,
  126. 'L', right + 20, centerY + 40,
  127. right + 10, centerY + 50,
  128. right + 20, centerY + 60,
  129. right - 10, centerY + 60,
  130. right, centerY + 50,
  131. right - 10, centerY + 60,
  132. right - 10, centerY + 50,
  133. right, centerY + 50,
  134. 'z'
  135. ])
  136. .attr({
  137. fill: badgeColor,
  138. stroke: '#FFFFFF',
  139. 'stroke-width': 1,
  140. zIndex: 5
  141. })
  142. .add();
  143. // 2009-2014
  144. years = this.renderer.text('2009-2014')
  145. .attr({
  146. zIndex: 6
  147. })
  148. .css({
  149. color: '#FFFFFF',
  150. fontStyle: 'italic',
  151. fontSize: '10px'
  152. })
  153. .add();
  154. years.attr({
  155. x: centerX - years.getBBox().width / 2,
  156. y: centerY + 62
  157. });
  158. // Prepare mouseover
  159. renderer = this.renderer;
  160. if (renderer.defs) { // is SVG
  161. $.each(this.get('employees').points, function () {
  162. var point = this,
  163. pattern;
  164. if (point.image) {
  165. pattern = renderer.createElement('pattern').attr({
  166. id: 'pattern-' + point.image,
  167. patternUnits: 'userSpaceOnUse',
  168. width: 400,
  169. height: 400
  170. }).add(renderer.defs);
  171. renderer.image(
  172. 'https://www.highcharts.com/images/employees2014/' + point.image + '.jpg',
  173. centerX - 80,
  174. centerY - 80,
  175. 160,
  176. 213
  177. ).add(pattern);
  178. Highcharts.addEvent(point, 'mouseOver', function () {
  179. empImage
  180. .attr({
  181. fill: 'url(#pattern-' + point.image + ')'
  182. })
  183. .animate({ opacity: 1 }, { duration: 500 });
  184. });
  185. Highcharts.addEvent(point, 'mouseOut', function () {
  186. empImage.animate({ opacity: 0 }, { duration: 500 });
  187. });
  188. }
  189. });
  190. }
  191. }
  192. var options = {
  193. chart: {
  194. events: {
  195. load: onChartLoad
  196. }
  197. },
  198. xAxis: {
  199. type: 'datetime',
  200. minTickInterval: 365 * 24 * 36e5,
  201. labels: {
  202. align: 'left'
  203. },
  204. plotBands: [{
  205. from: Date.UTC(2009, 10, 27),
  206. to: Date.UTC(2010, 11, 1),
  207. color: '#EFFFFF',
  208. label: {
  209. text: '<em>Offices:</em><br> Torstein\'s basement',
  210. style: {
  211. color: '#999999'
  212. },
  213. y: 180
  214. }
  215. }, {
  216. from: Date.UTC(2010, 11, 1),
  217. to: Date.UTC(2013, 9, 1),
  218. color: '#FFFFEF',
  219. label: {
  220. text: '<em>Offices:</em><br> Tomtebu',
  221. style: {
  222. color: '#999999'
  223. },
  224. y: 30
  225. }
  226. }, {
  227. from: Date.UTC(2013, 9, 1),
  228. to: Date.UTC(2014, 10, 27),
  229. color: '#FFEFFF',
  230. label: {
  231. text: '<em>Offices:</em><br> VikØrsta',
  232. style: {
  233. color: '#999999'
  234. },
  235. y: 30
  236. }
  237. }]
  238. },
  239. title: {
  240. text: 'Highcharts and Highsoft timeline'
  241. },
  242. tooltip: {
  243. style: {
  244. width: '250px'
  245. }
  246. },
  247. yAxis: [{
  248. max: 100,
  249. labels: {
  250. enabled: false
  251. },
  252. title: {
  253. text: ''
  254. },
  255. gridLineColor: 'rgba(0, 0, 0, 0.07)'
  256. }, {
  257. allowDecimals: false,
  258. max: 15,
  259. labels: {
  260. style: {
  261. color: Highcharts.getOptions().colors[2]
  262. }
  263. },
  264. title: {
  265. text: 'Employees',
  266. style: {
  267. color: Highcharts.getOptions().colors[2]
  268. }
  269. },
  270. opposite: true,
  271. gridLineWidth: 0
  272. }],
  273. plotOptions: {
  274. series: {
  275. marker: {
  276. enabled: false,
  277. symbol: 'circle',
  278. radius: 2
  279. },
  280. fillOpacity: 0.5
  281. },
  282. flags: {
  283. tooltip: {
  284. xDateFormat: '%B %e, %Y'
  285. }
  286. }
  287. },
  288. series: [{
  289. type: 'spline',
  290. id: 'google-trends',
  291. dashStyle: 'dash',
  292. name: 'Google search for <em>highcharts</em>',
  293. data: [{ x: 1258322400000, /* November 2009 */ y: 0 }, { x: 1260961200000, y: 5 }, { x: 1263639600000, y: 7 }, { x: 1266188400000, y: 5 }, { x: 1268740800000, y: 6 }, { x: 1271368800000, y: 8 }, { x: 1274004000000, y: 11 }, { x: 1276639200000, y: 9 }, { x: 1279274400000, y: 12 }, { x: 1281952800000, y: 13 }, { x: 1284588000000, y: 17 }, { x: 1287223200000, y: 17 }, { x: 1289858400000, y: 18 }, { x: 1292497200000, y: 20 }, { x: 1295175600000, y: 20 }, { x: 1297724400000, y: 27 }, { x: 1300276800000, y: 32 }, { x: 1302904800000, y: 29 }, { x: 1305540000000, y: 34 }, { x: 1308175200000, y: 34 }, { x: 1310810400000, y: 36 }, { x: 1313488800000, y: 43 }, { x: 1316124000000, y: 44 }, { x: 1318759200000, y: 42 }, { x: 1321394400000, y: 47 }, { x: 1324033200000, y: 46 }, { x: 1326711600000, y: 50 }, { x: 1329303600000, y: 57 }, { x: 1331899200000, y: 54 }, { x: 1334527200000, y: 59 }, { x: 1337162400000, y: 62 }, { x: 1339797600000, y: 66 }, { x: 1342432800000, y: 61 }, { x: 1345111200000, y: 68 }, { x: 1347746400000, y: 67 }, { x: 1350381600000, y: 73 }, { x: 1353016800000, y: 63 }, { x: 1355655600000, y: 54 }, { x: 1358334000000, y: 67 }, { x: 1360882800000, y: 74 }, { x: 1363435200000, y: 81 }, { x: 1366063200000, y: 89 }, { x: 1368698400000, y: 83 }, { x: 1371333600000, y: 88 }, { x: 1373968800000, y: 86 }, { x: 1376647200000, y: 81 }, { x: 1379282400000, y: 83 }, { x: 1381917600000, y: 95 }, { x: 1384552800000, y: 86 }, { x: 1387191600000, y: 83 }, { x: 1389870000000, y: 89 }, { x: 1392418800000, y: 90 }, { x: 1394971200000, y: 94 }, { x: 1397599200000, y: 100 }, { x: 1400234400000, y: 100 }, { x: 1402869600000, y: 99 }, { x: 1405504800000, y: 99 }, { x: 1408183200000, y: 93 }, { x: 1410818400000, y: 97 }, { x: 1413453600000, y: 98 }],
  294. tooltip: {
  295. xDateFormat: '%B %Y',
  296. valueSuffix: ' % of best month'
  297. }
  298. }, {
  299. name: 'Revenue',
  300. id: 'revenue',
  301. type: 'area',
  302. data: [[1257033600000, 2], [1259625600000, 3], [1262304000000, 2], [1264982400000, 3], [1267401600000, 4], [1270080000000, 4], [1272672000000, 4], [1275350400000, 4], [1277942400000, 5], [1280620800000, 7], [1283299200000, 6], [1285891200000, 9], [1288569600000, 10], [1291161600000, 8], [1293840000000, 10], [1296518400000, 13], [1298937600000, 15], [1301616000000, 14], [1304208000000, 15], [1306886400000, 16], [1309478400000, 22], [1312156800000, 19], [1314835200000, 20], [1317427200000, 32], [1320105600000, 34], [1322697600000, 36], [1325376000000, 34], [1328054400000, 40], [1330560000000, 37], [1333238400000, 35], [1335830400000, 40], [1338508800000, 38], [1341100800000, 39], [1343779200000, 43], [1346457600000, 49], [1349049600000, 43], [1351728000000, 54], [1354320000000, 44], [1356998400000, 43], [1359676800000, 43], [1362096000000, 52], [1364774400000, 52], [1367366400000, 56], [1370044800000, 62], [1372636800000, 66], [1375315200000, 62], [1377993600000, 63], [1380585600000, 60], [1383264000000, 60], [1385856000000, 58], [1388534400000, 65], [1391212800000, 52], [1393632000000, 72], [1396310400000, 57], [1398902400000, 70], [1401580800000, 63], [1404172800000, 65], [1406851200000, 65], [1409529600000, 89], [1412121600000, 100]],
  303. tooltip: {
  304. xDateFormat: '%B %Y',
  305. valueSuffix: ' % of best month'
  306. }
  307. }, {
  308. yAxis: 1,
  309. name: 'Highsoft employees',
  310. id: 'employees',
  311. type: 'area',
  312. step: 'left',
  313. tooltip: {
  314. headerFormat: '<span style="font-size: 11px;color:#666">{point.x:%B %e, %Y}</span><br>',
  315. pointFormat: '{point.name}<br><b>{point.y}</b>',
  316. valueSuffix: ' employees'
  317. },
  318. data: [
  319. { x: Date.UTC(2009, 10, 1), y: 1, name: 'Torstein worked alone', image: 'Torstein' },
  320. { x: Date.UTC(2010, 10, 20), y: 2, name: 'Grethe joined', image: 'Grethe' },
  321. { x: Date.UTC(2011, 3, 1), y: 3, name: 'Erik joined', image: null },
  322. { x: Date.UTC(2011, 7, 1), y: 4, name: 'Gert joined', image: 'Gert' },
  323. { x: Date.UTC(2011, 7, 15), y: 5, name: 'Hilde joined', image: 'Hilde' },
  324. { x: Date.UTC(2012, 5, 1), y: 6, name: 'Guro joined', image: 'Guro' },
  325. { x: Date.UTC(2012, 8, 1), y: 5, name: 'Erik left', image: null },
  326. { x: Date.UTC(2012, 8, 15), y: 6, name: 'Anne Jorunn joined', image: 'AnneJorunn' },
  327. { x: Date.UTC(2013, 0, 1), y: 7, name: 'Hilde T. joined', image: null },
  328. { x: Date.UTC(2013, 7, 1), y: 8, name: 'Jon Arild joined', image: 'JonArild' },
  329. { x: Date.UTC(2013, 7, 20), y: 9, name: 'Øystein joined', image: 'Oystein' },
  330. { x: Date.UTC(2013, 9, 1), y: 10, name: 'Stephane joined', image: 'Stephane' },
  331. { x: Date.UTC(2014, 9, 1), y: 11, name: 'Anita joined', image: 'Anita' },
  332. { x: Date.UTC(2014, 10, 27), y: 11, name: ' ', image: null }
  333. ]
  334. }]
  335. };
  336. // Add flags for important milestones. This requires Highstock.
  337. if (Highcharts.seriesTypes.flags) {
  338. options.series.push({
  339. type: 'flags',
  340. name: 'Cloud',
  341. color: '#333333',
  342. shape: 'squarepin',
  343. y: -80,
  344. data: [
  345. { x: Date.UTC(2014, 4, 1), text: 'Highcharts Cloud Beta', title: 'Cloud', shape: 'squarepin' }
  346. ],
  347. showInLegend: false
  348. }, {
  349. type: 'flags',
  350. name: 'Highmaps',
  351. color: '#333333',
  352. shape: 'squarepin',
  353. y: -55,
  354. data: [
  355. { x: Date.UTC(2014, 5, 13), text: 'Highmaps version 1.0 released', title: 'Maps' }
  356. ],
  357. showInLegend: false
  358. }, {
  359. type: 'flags',
  360. name: 'Highcharts',
  361. color: '#333333',
  362. shape: 'circlepin',
  363. data: [
  364. { x: Date.UTC(2009, 10, 27), text: 'Highcharts version 1.0 released', title: '1.0' },
  365. { x: Date.UTC(2010, 6, 13), text: 'Ported from canvas to SVG rendering', title: '2.0' },
  366. { x: Date.UTC(2010, 10, 23), text: 'Dynamically resize and scale to text labels', title: '2.1' },
  367. { x: Date.UTC(2011, 9, 18), text: 'Highstock version 1.0 released', title: 'Stock', shape: 'squarepin' },
  368. { x: Date.UTC(2012, 7, 24), text: 'Gauges, polar charts and range series', title: '2.3' },
  369. { x: Date.UTC(2013, 2, 22), text: 'Multitouch support, more series types', title: '3.0' },
  370. { x: Date.UTC(2014, 3, 22), text: '3D charts, heatmaps', title: '4.0' }
  371. ],
  372. showInLegend: false
  373. }, {
  374. type: 'flags',
  375. name: 'Events',
  376. color: '#333333',
  377. fillColor: 'rgba(255,255,255,0.8)',
  378. data: [
  379. { x: Date.UTC(2012, 10, 1), text: 'Highsoft won "Entrepeneur of the Year" in Sogn og Fjordane, Norway', title: 'Award' },
  380. { x: Date.UTC(2012, 11, 25), text: 'Packt Publishing published <em>Learning Highcharts by Example</em>. Since then, many other books are written about Highcharts.', title: 'First book' },
  381. { x: Date.UTC(2013, 4, 25), text: 'Highsoft nominated Norway\'s Startup of the Year', title: 'Award' },
  382. { x: Date.UTC(2014, 4, 25), text: 'Highsoft nominated Best Startup in Nordic Startup Awards', title: 'Award' }
  383. ],
  384. onSeries: 'revenue',
  385. showInLegend: false
  386. });
  387. }
  388. $('#container').highcharts(options);
  389. </script>
  390. </body>
  391. </html>