-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.go
98 lines (82 loc) · 1.68 KB
/
graph.go
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
package main
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
)
var template = `
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.bundle.min.js"></script>
<style type="text/css">
</style>
<title></title>
<script type="text/javascript">
window.onload=function(){
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'scatter',
data: {
datasets: [{
label: 'power',
data: %s
}]
},
options: {
scales: {
xAxes: [{
type: 'logarithmic',
position: 'bottom'
}],
yAxes: [{
type: 'logarithmic',
position: 'left'
}]
}
}
});
}
</script>
</head>
<body>
<div style="width:600px">
<canvas id="myChart" width="400" height="400"></canvas>
</div>
<script>
</script>
</body>
`
type pair struct {
X float64 `json:"x"`
Y float64 `json:"y"`
}
// PairsJSON will take a pair of values and output as json
func PairsJSON(data []pair) string {
dataJSON, err := json.Marshal(data)
if err != nil {
fmt.Println(err)
}
dataString := fmt.Sprintf("%s", dataJSON)
return dataString
}
// PowerJSON will reformat the data
func PowerJSON(data []power) string {
dataJSON, err := json.Marshal(data)
if err != nil {
fmt.Println(err)
}
dataString := fmt.Sprintf("%s", dataJSON)
return dataString
}
// OutputHTML will write the output graph
func OutputHTML(dir string, path string, jsonData string) {
f, err := os.Create(filepath.Join(dir, path))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Fprintf(f, "test data")
fmt.Fprintf(f, template, jsonData)
}