FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
mathjs/examples/browser/plot.html at develop · Eternal-Rise/mathjs · GitHub
Eternal-Rise
/
mathjs
Public
forked from
josdejong/mathjs
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
mathjs
/
examples
/
browser
/
plot.html
Copy path
More file actions
More file actions
Latest commit
History
History
History
78 lines (66 loc) · 1.53 KB
Breadcrumbs
mathjs
/
examples
/
browser
/
plot.html
Copy path
File metadata and controls
78 lines (66 loc) · 1.53 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<!DOCTYPE html
>
<
html
lang
="
en
"
>
<
head
>
<
meta
charset
="
utf-8
"
>
<
title
>
math.js | plot
</
title
>
<
script
src
="
../../lib/browser/math.js
"
>
</
script
>
<
script
src
="
https://cdn.plot.ly/plotly-1.35.2.min.js
"
>
</
script
>
<
style
>
input
[
type
=
text
] {
width
:
300
px
;
}
input
{
padding
:
6
px
;
}
body
,
html
,
input
{
font-family
:
sans-serif;
font-size
:
11
pt
;
}
form
{
margin
:
20
px
0
;
}
</
style
>
</
head
>
<
body
>
<
form
id
="
form
"
>
<
label
for
="
eq
"
>
Enter an equation:
</
label
>
<
input
type
="
text
"
id
="
eq
"
value
="
4 * sin(x) + 5 * cos(x/2)
"
/>
<
input
type
="
submit
"
value
="
Draw
"
/>
</
form
>
<
div
id
="
plot
"
>
</
div
>
<
p
>
Used plot library:
<
a
href
="
https://plot.ly/javascript/
"
>
Plotly
</
a
>
</
p
>
<
script
>
function
draw
(
)
{
try
{
// compile the expression once
const
expression
=
document
.
getElementById
(
'eq'
)
.
value
const
expr
=
math
.
compile
(
expression
)
// evaluate the expression repeatedly for different values of x
const
xValues
=
math
.
range
(
-
10
,
10
,
0.5
)
.
toArray
(
)
const
yValues
=
xValues
.
map
(
function
(
x
)
{
return
expr
.
evaluate
(
{
x
:
x
}
)
}
)
// render the plot using plotly
const
trace1
=
{
x
:
xValues
,
y
:
yValues
,
type
:
'scatter'
}
const
data
=
[
trace1
]
Plotly
.
newPlot
(
'plot'
,
data
)
}
catch
(
err
)
{
console
.
error
(
err
)
alert
(
err
)
}
}
document
.
getElementById
(
'form'
)
.
onsubmit
=
function
(
event
)
{
event
.
preventDefault
(
)
draw
(
)
}
draw
(
)
</
script
>
</
body
>
</
html
>
Back
|
FazBrowse Home
|
New Git URL