forked from Rod2012/HTMLtable2chart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readme.html
224 lines (203 loc) · 5.88 KB
/
readme.html
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>HTMLtable2chart Column Chart</title>
<script type="text/javascript" src="js/HTMLtable2chart/graficarBarras.js"></script>
<script type="text/javascript" src="js/HTMLtable2chart/tabla2array.js"></script>
<style type="text/css">
th{
border: 1px solid black;
background-color: #d4d1dd;
}
td{
border: 1px solid black;
text-align: center;
}
pre{
font-family: "Courier New" Courier monospace;
background-color: #eeeeee;
}
</style>
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
</head>
<body>
<h1>HTMLtable2chart</h1>
<hr>
Version: 0.1.0
HTMLtable2chart is a javascript library written to convert data that is in a HTML table into chart which is an image over a HTML5 canvas tag
<br>
It was created to replace some charts made with the PHP JpGraph library.
<h2>Prerequisites</h2>
As this library will run in a client's browser, it will depend mainly whether that browser implement <code><canvas></code> tag
<h2>What's included</h2>
<pre>
HTMLtable2chart/
├── doc/
│ └──examples/
│ ├──en/
│ └──es/
│ ├── columnas.html
│ ├── lineas.html
│ └── tortas.html
├── img/
│ ├── bandera.png
│ ├── barras.png
│ ├──
│ └──
├── js/
│ └──HTMLtable2chart/
│ ├── graficarBarras.js
│ ├── graficarTortas.js
│ ├── graficarXY.js
│ └── tabla2array.js
├── readme.html
└── README.md
</pre>
<h2>How to use</h2>
If you have a html table like this:
<br>
<table id="myTable">
<thead>
<tr>
<th></th>
<th>Canada</th>
<th>USA</th>
<th>Mexico</th>
<th>Venezuela</th>
</tr>
</thead>
<tbody>
<tr>
<td>Male</td>
<td>1685</td>
<td>734</td>
<td>278</td>
<td>1582</td>
</tr>
<tr>
<td>Female</td>
<td>1521</td>
<td>509</td>
<td>210</td>
<td>1344</td>
</tr>
</tbody>
</table>
<br>
Created with the following <b>html</b> code
<pre class="prettyprint">
<code>
<table id="myTable">
<thead>
<tr>
<th></th>
<th>Canada</th>
<th>USA</th>
<th>Mexico</th>
<th>Venezuela</th>
</tr>
</thead>
<tbody>
<tr>
<td>Male</td>
<td>1685</td>
<td>734</td>
<td>278</td>
<td>1582</td>
</tr>
<tr>
<td>Female</td>
<td>1521</td>
<td>509</td>
<td>210</td>
<td>1344</td>
</tr>
</tbody>
</table>
</code>
</pre>
Download this pack and you just put the <code>.js</code> files into appropriated path in your project, then add to <code><head></code> element
in your document the following script tags, as you have done before with any other javascript library
<pre class="prettyprint">
<code>
<script type="text/javascript" src="js/HTMLtable2chart/graficarTortas.js"></script>
<script type="text/javascript" src="js/HTMLtable2chart/tabla2array.js"></script>
</code>
</pre>
You must add a canvas element to the place where you want the chart to be.
<pre class="prettyprint">
<code>
<canvas id="grafico2" width="750" height="480" style="border: 1px solid black;">Canvas is not supported</canvas>
</code>
</pre>
Finally, you add at the end of your document the following code, to set some parameters and call function to build the chart
<pre class="prettyprint">
<code>
<script type="text/javascript">
var misParam ={
miMargen : 0.80,
separZonas : 0.05,
tituloGraf : "Title of Chart",
tituloEjeX : "X axis title",
tituloEjeY : "Y Axis title",
nLineasDiv : 10,
mysColores :[
["rgba(93,18,18,1)","rgba(196,19,24,1)"], //red
["rgba(171,115,51,1)","rgba(251,163,1,1)"], //yellow
],
anchoLinea : 2,
};
obtener_datos_tabla_convertir_en_array('myTable',graficarBarras,'grafico2','750','480',misParam,false);
</script>
</code>
</pre>
Then, you will have
<br>
<canvas id="grafico2" width="750" height="480" style="border: 1px solid black;">No soporta canvas</canvas>
<img id="myFondo" alt="" src="img/bandera.png" style="display: none;">
<br>
And that's all.
<br>
<!-- <canvas id="grafico" width="750" height="480" style="border: 1px solid black;">No soporta canvas</canvas> -->
<h2>What's type of charts are available?</h2>
In this version you can find:
<ul>
<li>Column</li>
<li>Pie</li>
<li>Line (XY)</li>
</ul>
<h2>Authors</h2>
<ul>
<li>Rodney Salcedo <a href="https://github.com/Rod2012">@Rod2012</a></li>
</ul>
See the plural, others contributors are welcome...
<h2>License</h2>
This software is released under GNU Affero General Public License <a href="https://www.gnu.org/licenses/agpl-3.0.html">AGPLv3</a>
<h2>Acknowledgments</h2>
<ul>
<li>PHP JpGraph library, now powered by Asial Corporation </li>
</ul>
</body>
<script type="text/javascript">
var misParam ={
miMargen : 0.80,
separZonas : 0.05,
tituloGraf : "Title of Chart",
tituloEjeX : "X axis title",
tituloEjeY : "Y Axis title",
nLineasDiv : 10,
mysColores :[
["rgba(93,18,18,1)","rgba(196,19,24,1)"], //rojos
["rgba(171,115,51,1)","rgba(251,163,1,1)"], //amarillos
["rgba(9,54,11,1)","rgba(196,255,24,1)"], //verdes
["rgba(0,10,93,1)","rgba(0,0,200,1)"], //azules
["rgba(93,93,93,1)","rgba(150,150,150,1)"] //grises
],
anchoLinea : 2,
radioTorta : 0.4
};
obtener_datos_tabla_convertir_en_array('myTable',graficarBarras,'grafico2','750','480',misParam,false);
//obtener_datos_tabla_convertir_en_array('myTable',graficarBarras,'grafico','750','480',misParam,true);
</script>
</html>