gettingstarted.html.haml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. .container.sidemenu
  2. .row
  3. .large-3.medium-4.columns.column-menu
  4. .side-bar
  5. %ul.side-nav
  6. %li GETTING STARTED
  7. %li
  8. %a( href="#setup" ) 1. Setup
  9. %li
  10. %a( href="#generate" ) 2. Generate chart
  11. %li
  12. %a( href="#customize" ) 3. Customize chart
  13. %li
  14. %a( href="#api" ) 4. Use APIs
  15. %li
  16. %a( href="#style" ) 5. Customize style
  17. %li
  18. %a( href="#more" ) 6. And more..
  19. .large-9.medium-8.columns.column-content
  20. %section
  21. %h2 Getting Started
  22. %p In this guide, we are going to show you how to get started with C3.
  23. %hr
  24. %section
  25. %h3
  26. %a( href="#setup" ) 1. Setup
  27. %p Download the latest version here:
  28. %ul
  29. %li <a href="https://github.com/c3js/c3/releases/latest" target="_blank">https://github.com/c3js/c3/releases/latest</a>
  30. %p Installing by Bower/Component is also available with the name <span class="code">c3</span>.
  31. %p Then, load the scripts and css:
  32. .sourcecode.highlight
  33. %pre
  34. %code.html.xml
  35. :preserve
  36. <span class="comment">&lt;!-- Load c3.css --&gt;</span>
  37. <span class="tag">&lt;<span class="title">link</span> <span class="attribute">href</span>=<span class="value">"/path/to/c3.css"</span> <span class="attribute">rel</span>=<span class="value">"stylesheet"</span>&gt;</span>
  38. <span class="comment">&lt;!-- Load d3.js and c3.js --&gt;</span>
  39. <span class="tag">&lt;<span class="title">script</span> <span class="attribute">src</span>=<span class="value">"/path/to/d3.v5.min.js"</span> <span class="attribute">charset</span>=<span class="value">"utf-8"</span>&gt;</span><span class="tag">&lt;/<span class="title">script</span>&gt;</span>
  40. <span class="tag">&lt;<span class="title">script</span> <span class="attribute">src</span>=<span class="value">"/path/to/c3.min.js"</span>&gt;</span><span class="tag">&lt;/<span class="title">script</span>&gt;</span>
  41. %p C3 depends on D3, so please load D3 too.
  42. %hr
  43. %section
  44. %h3
  45. %a( href="#generate" ) 2. Generate Chart
  46. %p C3 generates a chart by calling <span class="code">generate()</span> with the argument object, and an element including the chart will insert into the element specified as a selector in that argument as <span class="code">bindto</span>.
  47. %p Prepare the element to bind the chart:
  48. .sourcecode.highlight
  49. %pre
  50. %code.html.xml
  51. :preserve
  52. <span class="tag">&lt;<span class="title">div</span> <span class="attribute">id</span>=<span class="value">"chart"</span>&gt;&lt;/<span class="title">div</span>&gt;</span>
  53. %p And, call <span class="code">generate()</span> with arguments:
  54. .sourcecode.highlight
  55. %pre
  56. %code.javascript
  57. :preserve
  58. var chart = c3.generate({
  59. bindto: '#chart',
  60. data: {
  61. columns: [
  62. ['data1', 30, 200, 100, 400, 150, 250],
  63. ['data2', 50, 20, 10, 40, 15, 25]
  64. ]
  65. }
  66. });
  67. %p C3 supports the asynchronous module definition (AMD) API. If you use <a href="http://requirejs.org/" target="_blank">RequireJS</a>, you can load like this:
  68. .sourcecode.highlight
  69. %pre
  70. %code.javascript
  71. :preserve
  72. require.config({
  73. baseUrl: '/js',
  74. paths: {
  75. d3: "http://d3js.org/d3.v5.min"
  76. }
  77. });
  78. require(["d3", "c3"], function(d3, c3) {
  79. c3.generate({
  80. ...
  81. });
  82. });
  83. %p Then, you will see the chart:
  84. #chart2_1
  85. %br
  86. %p Data can be loaded as <a href="/samples/data_columned.html">columned data</a> / <a href="/samples/data_rowed.html">rowed data</a> / <a href="/samples/data_url.html">csv in URL</a>.
  87. %p There are serveral options to customize the chart and you can see those here:
  88. %ul
  89. %li <a href="/examples.html">Examples</a>
  90. %hr
  91. %section
  92. %h3
  93. %a( href="#customize" ) 3. Customize Chart
  94. %p The chart can be customize by giving some options when generating. We will introduce some of them here.
  95. %h4 1. Additional Axis
  96. %p Introduce additional axis for <span class="code">data2</span>. Add <span class="code">data.axes</span> and <span class="code">axis.y2.show</span> as follows:
  97. .sourcecode.highlight
  98. %pre
  99. %code.javascript
  100. :preserve
  101. var chart = c3.generate({
  102. bindto: '#chart',
  103. data: {
  104. columns: [
  105. ['data1', 30, 200, 100, 400, 150, 250],
  106. ['data2', 50, 20, 10, 40, 15, 25]
  107. ],
  108. axes: {
  109. data2: 'y2' // ADD
  110. }
  111. },
  112. axis: {
  113. y2: {
  114. show: true // ADD
  115. }
  116. }
  117. });
  118. %p Then, the chart will be like this:
  119. #chart3_1
  120. %br
  121. %h4 2. Show Axis Label
  122. %p Show labels for each axis. Add <span class="code">axis.y.label</span> and <span class="code">axis.y2.label</span> as follows:
  123. .sourcecode.highlight
  124. %pre
  125. %code.javascript
  126. :preserve
  127. var chart = c3.generate({
  128. bindto: '#chart',
  129. data: {
  130. columns: [
  131. ['data1', 30, 200, 100, 400, 150, 250],
  132. ['data2', 50, 20, 10, 40, 15, 25]
  133. ],
  134. axes: {
  135. data2: 'y2'
  136. }
  137. },
  138. axis: {
  139. y: {
  140. label: { // ADD
  141. text: 'Y Label',
  142. position: 'outer-middle'
  143. }
  144. },
  145. y2: {
  146. show: true,
  147. label: { // ADD
  148. text: 'Y2 Label',
  149. position: 'outer-middle'
  150. }
  151. }
  152. }
  153. });
  154. %p Then, the chart will be like this:
  155. #chart3_2
  156. %br
  157. %h4 3. Change Chart Type
  158. %p Show <span class="code">data2</span> as Bar chart. Add <span class="code">data.types</span> as follows:
  159. .sourcecode.highlight
  160. %pre
  161. %code.javascript
  162. :preserve
  163. var chart = c3.generate({
  164. bindto: '#chart',
  165. data: {
  166. columns: [
  167. ['data1', 30, 200, 100, 400, 150, 250],
  168. ['data2', 50, 20, 10, 40, 15, 25]
  169. ],
  170. axes: {
  171. data2: 'y2'
  172. },
  173. types: {
  174. data2: 'bar' // ADD
  175. }
  176. },
  177. axis: {
  178. y: {
  179. label: {
  180. text: 'Y Label',
  181. position: 'outer-middle'
  182. }
  183. },
  184. y2: {
  185. show: true,
  186. label: {
  187. text: 'Y2 Label',
  188. position: 'outer-middle'
  189. }
  190. }
  191. }
  192. });
  193. %p Then, the chart will be like this:
  194. #chart3_3
  195. %br
  196. %h4 4. Format values
  197. %p Format the values of each data. Add <span class="code">axis.y.tick.format</span> as follows:
  198. .sourcecode.highlight
  199. %pre
  200. %code.javascript
  201. :preserve
  202. var chart = c3.generate({
  203. bindto: '#chart',
  204. data: {
  205. columns: [
  206. ['data1', 30, 200, 100, 400, 150, 250],
  207. ['data2', 50, 20, 10, 40, 15, 25]
  208. ],
  209. axes: {
  210. data2: 'y2'
  211. },
  212. types: {
  213. data2: 'bar'
  214. }
  215. },
  216. axis: {
  217. y: {
  218. label: {
  219. text: 'Y Label',
  220. position: 'outer-middle'
  221. },
  222. tick: {
  223. format: d3.format("$,") // ADD
  224. }
  225. },
  226. y2: {
  227. show: true,
  228. label: {
  229. text: 'Y2 Label',
  230. position: 'outer-middle'
  231. }
  232. }
  233. }
  234. });
  235. %p Then, the chart will be like this:
  236. #chart3_4
  237. %br
  238. %p More information about the options, please see <a href="/examples.html">Examples</a>. (We'll add the reference soon)
  239. %hr
  240. %section
  241. %h3
  242. %a( href="#api" ) 4. Use APIs
  243. %p By using APIs, you can update the chart after it's been rendered. We will introduce some of APIs here. APIs can be called through the object returned from <span class="code">generate()</span>.
  244. %h4 1. Load Data
  245. %p By using <span class="code">load()</span> API, you can load data and update the chart dynamically as follows:
  246. .sourcecode.highlight
  247. %pre
  248. %code.javascript
  249. :preserve
  250. // var chart = c3.generate({ ... });
  251. chart.load({
  252. columns: [
  253. ['data1', 300, 100, 250, 150, 300, 150, 500],
  254. ['data2', 100, 200, 150, 50, 100, 250]
  255. ]
  256. });
  257. %p If you push the button "Load" below, this code will run and the chart will be updated.
  258. %button.small( onclick="example4_1();" ) Load
  259. #chart4_1
  260. %br
  261. %h4 2. Unload Data
  262. %p By using <span class="code">unload()</span> API, you can unload the data dynamically as follows:
  263. .sourcecode.highlight
  264. %pre
  265. %code.javascript
  266. :preserve
  267. // var chart = c3.generate({ ... });
  268. chart.unload({
  269. ids: ['data2', 'data3']
  270. });
  271. %p If you push the button "Unload" below, this code will run and the chart will be updated.
  272. %button.small( onclick="example4_2();" ) Unload
  273. #chart4_2
  274. %br
  275. %p Please use <span class="code">unload</span> param in <span class="code">load()</span> API if load and unload need to run simultaneously. Please see <a href="/samples/data_load.html">this example</a>.
  276. %h4 3. Show/Hide Data
  277. %p By using <span class="code">show()</span> and <span class="code">hide()</span> API, you can show/hide the data dynamically as follows:
  278. .sourcecode.highlight
  279. %pre
  280. %code.javascript
  281. :preserve
  282. // var chart = c3.generate({ ... });
  283. chart.hide(['data2', 'data3']);
  284. chart.show(['data2', 'data3']);
  285. %p If you push the button "Show" and "Hide" below, this code will run and the chart will be updated.
  286. %button.small( onclick="example4_3_2();" ) Hide
  287. %button.small( onclick="example4_3_1();" ) Show
  288. #chart4_3
  289. %br
  290. %p The documentation about APIs is poor now, so please check the <a href="https://github.com/c3js/c3/issues?state=open">issues on github</a>. There might be some hints about what you want to do. (We will add the document soon)
  291. %hr
  292. %section
  293. %h3
  294. %a( href="#style" ) 5. Customize Style
  295. %p C3 give some classes for each element when generating. So, you can change the style of the elements by using those classes.
  296. %h4 1. Line style
  297. %p The lines have <span class="code">c3-line-[id]</span> class, so this class can be used to define the style in css as follows:
  298. .sourcecode.highlight
  299. %pre
  300. %code.css
  301. :preserve
  302. #chart .c3-line-data2 {
  303. stroke-width: 5px;
  304. }
  305. #chart5_1
  306. %br
  307. %p Please check the class for each element if you want to change the style. Web Inspector would be useful. (We will add the document for class definition soon)
  308. %hr
  309. %section
  310. %h3
  311. %a( href="#more" ) 6. And More..
  312. %p Please check the <a href="/examples.html">examples</a> and the <a href="https://github.com/c3js/c3/issues?state=open">issues</a> on github for more information. Sorry for the poor documentation. We're working on now and please give me some time. Thank you.
  313. = partial :footer
  314. = partial :script
  315. = partial :script_scroll
  316. = javascript_include_tag 'gettingstarted.js'