func genGraphHTML(te *timelineEvent, id int) string {
	keys := []string{}
	values := []uint64{}
	for _, b := range *te.Metrics.Histogram {
		for k, v := range b {
			keys = append(keys, k)
			values = append(values, v)
		}
	}
	keysj, _ := json.Marshal(keys)
	valuesj, _ := json.Marshal(values)
	out := strings.Replace(graph, "XCANVASID", strconv.Itoa(id), 1)
	out = strings.Replace(out, "XKEYS", string(keysj), 1)
	out = strings.Replace(out, "XVALUES", string(valuesj), 1)
	return out
}
genGraphHTML takes a *timelineEvent and id (used for each graph
html element ID) and creates a chart.js graph output.
package tachymeter
import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"path/filepath"
	"strconv"
	"strings"
	"time"
)
type Timeline struct {
	timeline []*timelineEvent
}
type timelineEvent struct {
	Metrics *Metrics
	Created time.Time
}
func (t *Timeline) AddEvent(m *Metrics) {
	t.timeline = append(t.timeline, &timelineEvent{
		Metrics: m,
		Created: time.Now(),
	})
}
func (t *Timeline) WriteHTML(p string) error {
	path, err := filepath.Abs(p)
	if err != nil {
		return err
	}
	var b bytes.Buffer
	b.WriteString(head)
	for n := range t.timeline {
		b.WriteString(fmt.Sprintf(`%s<div class="graph">%s`, tab, nl))
		b.WriteString(fmt.Sprintf(`%s%s<canvas id="canvas-%d"></canvas>%s`, tab, tab, n, nl))
		b.WriteString(fmt.Sprintf(`%s</div>%s`, tab, nl))
		b.WriteString(fmt.Sprintf(`%s<div class="info">%s`, tab, nl))
		b.WriteString(fmt.Sprintf(`%s<p><h2>Iteration %d</h2>%s`, tab, n+1, nl))
		b.WriteString(t.timeline[n].Metrics.String())
		b.WriteString(fmt.Sprintf("%s%s</p></div>%s", nl, tab, nl))
	}
	for id, m := range t.timeline {
		s := genGraphHTML(m, id)
		b.WriteString(s)
	}
	b.WriteString(tail)
	d := []byte(b.String())
	fname := fmt.Sprintf("%s/tachymeter-%d.html", path, time.Now().Unix())
	err = ioutil.WriteFile(fname, d, 0644)
	if err != nil {
		return err
	}
	return nil
}