playing around with plotly and highchart
This commit is contained in:
1 parent
06f77aea35
commit
16345cf224
3 files changed
+198
-82
No files matched your search
+109
@@ -0,0 +1,109 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 43,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"(require '[clojupyter.misc.display :as display]\n",
|
||||
" '[hiccup.core :as hiccup]\n",
|
||||
" '[cheshire.core :as cheshire]\n",
|
||||
" '[clojure.repl :refer :all]) ;; to have all the repl goodies"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 44,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<script src=\"https://code.highcharts.com/highcharts.js\"></script>"
|
||||
]
|
||||
},
|
||||
"execution_count": 44,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"(display/make-html (hiccup/html [:script {:src \"https://code.highcharts.com/highcharts.js\"}]))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 45,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"#'user/plot-highchart"
|
||||
]
|
||||
},
|
||||
"execution_count": 45,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"(defn plot-highchart [highchart-json]\n",
|
||||
" (let [id (str (java.util.UUID/randomUUID))\n",
|
||||
" code (format \"Highcharts.chart('%s', %s );\" id, (cheshire/encode highchart-json))\n",
|
||||
" html [:div [:div {:id id}]\n",
|
||||
" [:script code]]]\n",
|
||||
" (-> html hiccup/html display/make-html)))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 63,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div><div id=\"b2087289-fc86-4ccb-8cf7-3704197ee8bc\"></div><script>Highcharts.chart('b2087289-fc86-4ccb-8cf7-3704197ee8bc', {\"chart\":{\"type\":\"line\"},\"title\":{\"text\":\"Plot of random data\"},\"series\":[{\"data\":[307.5087671164324,3048.5432765685828,4539.2994089997,6307.544109325754,7340.475495223804,9008.812104906117,11952.293451926853,13555.936842133238,14877.581203585052,16507.36729804958,18446.740324016977,20208.868609062723,20845.59793918523,22826.806946988774,24032.974265374516,26595.971193882564,27624.03584687947,29393.822635533612,31406.755586844174,33166.420640715,34867.557730237684,36939.79245820188,38985.256695095166,40253.00080084487,41685.78763792553,42920.22397875178,46062.36485308066,47264.22874044051,48418.30200450214,51471.92279939544,51902.80396533318,53252.272538754485,56086.92407888982,57255.62583014506,58843.22100312766,60806.06578306819,62641.3996908148,63659.326016826584,65432.652874356674,67685.32427652241,69930.11376127541,70651.62942967306,72580.68386098354,74478.09697012536,77000.71447990686,77963.22303578029,79445.12362511316,82244.03286501515,82862.34434360835,85113.89565564503,86266.1796376803,88641.72223647543,90485.63330530454,91924.54182880478,94100.8679105561,96027.27078538758,96538.69277579446,98302.19267751921,101105.80050258152,101576.69147594726,104193.05437638875,106297.35529478529,107338.50760164208,108930.74941306494,110226.83149415285,113250.8059667718,113813.09631410723,115491.57063474412,116927.3369438092,119195.47059879071,120839.31828459997,122219.6272945593,124715.97296229452,125858.13901986965,128571.01244005401,130091.63649767994,131628.41664591437,133055.4982404276,134634.40929228594,136448.4613548598,138234.9561156447,139755.33282135974,142302.9261721284,143391.27891921662,144535.28903830302,147020.7290225477,148700.8549492777,149470.07936865644,151117.17814594848,153916.73241389482,156133.73534523128,157578.98803029017,158061.06483552957,160975.14709854656,162866.22894401147,164567.95147249915,165491.07386668384,166616.02825800757,168538.95203688252,171012.0048788405,172984.79970998733,174985.90695047035,175349.99546087286,177991.63944749333,178715.8465943433,181416.90104251288,183328.75443313044,184178.71335466218,186350.3018318015,187217.60274465688,189279.2100978575,191107.90110215143,193735.15338741304,194451.9976155642,195686.95015824685,198131.8519459872,199583.12054451965,202390.65795548348,202624.98398536432,205293.02849778708,206458.44764469165,207881.0663009042,210861.80414176683,211780.62296106963,214309.9187083863,215237.16358888167,217495.16355640333,218180.99812596862,219940.68224997708,222184.07989580886,223550.68400054413,224858.77782610772,228113.43257904192,229932.4928834055,231359.67980569226,231731.01046354265,234316.07671224634,235878.17432120576,237457.47617558928,240086.7560799895,241169.2216895069,243062.0208332987,245286.01983312407,246970.9981781978,247670.65078517035,249072.2309775485,252206.7260954204,253326.95666441147,254251.4123092306,257107.2765264146,257767.2736524727,260170.67996259758,262283.22838585934,262553.93117326696,265347.45518378244,267292.2191937826,268195.63724212686,270028.85657750757,271498.20971286186,273910.7388992814,275649.6143861772,276545.1103853174,279264.60809853184,280712.59389295976,281608.3757035826,284764.42750911316,285971.8321777921,287179.70321654156,289329.6476490395,290258.2409615706,292949.08310903807,294526.477593167,296052.89536074566,297089.14542446187,298961.8728083464,301131.10737858457,302161.8336117883,303815.87085835316,307054.2989349738,308451.19458921184,309199.000800272,311662.8211698427,312929.67086613935,314070.51204780233,316595.25911144353,317659.8469845267,319616.251145623,321185.10009355104,323184.7908274676,324977.1587810999,327378.89425340196,329434.9606195401,330689.4928178508,331870.1510650484,333143.01102066634,335910.2846428376,337523.6278765461,339613.39568016713,339794.5545770101,342612.4508288325,343674.17451928806,346526.1761223459,347876.62031677493,349169.9571030041,351230.52279254445,352813.6726592407,354207.76972461934,355245.9992189914,357056.9962813506,359524.2717569389,361075.33475147444,363399.58533170144,364951.13799612893,365758.4613386001,367684.726678071,369999.8768820188,370857.7783273361,372422.38636399666,375433.1697381066,376303.87141539034,377737.6122279091,379719.3783247004,380971.2982417276,382686.59424794605,385271.34326185373,386139.6345567596,389294.7009660037,389932.64080839447,392420.40984513436,393733.71269337356,395869.7659889891,397662.2136271285,399614.8913708115,401371.6173837503,401812.07342362625,403801.7224318507,406202.3979313176,406863.996293252,408685.1034754239,410458.56698854105,412856.58042772824,414987.3242883186,416856.17162498983,418609.89876580355,420158.3544090097,421670.9441462959,423235.2719834055,423885.9573073304,427019.0127011691,428126.4442312382,429922.90467548487,431200.0033887229,433112.11001992645,435661.0933026573,436992.98278276395,439000.922102553,439736.3329128806,442676.91429842426,442764.Line truncated
|
||||
]
|
||||
},
|
||||
"execution_count": 63,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"(def raw-data (map #(+ (* 22 (+ % (Math/random)) 78)) (range)))\n",
|
||||
"(def data-1 (take 1000 raw-data))\n",
|
||||
"(def data-2 (take 1000 (drop 1000 raw-data)))\n",
|
||||
"\n",
|
||||
"(plot-highchart {:chart {:type \"line\"}\n",
|
||||
" :title {:text \"Plot of random data\"}\n",
|
||||
" :series [{:data data-1} {:data data-2}]})"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Lein-Clojure",
|
||||
"language": "clojure",
|
||||
"name": "lein-clojure"
|
||||
},
|
||||
"language_info": {
|
||||
"file_extension": ".clj",
|
||||
"mimetype": "text/x-clojure",
|
||||
"name": "clojure",
|
||||
"version": "1.9.0-RC1"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Reference in new issue
Block a user