<div id="graph-example" class="graph-example hx-margin"></div>
var graph = new hx.Graph('#graph-example')
var axis = graph.addAxis({
x: {
title: 'Time'
},
y: {
title: 'Value',
scalePaddingMax: 0.1
}
})
var randomSign = function(){
return Math.random() > 0.5 ? 1 : 0
}
var createData = function(a, b, c) {
var offset = 0.1 + Math.random()
return hx.range(50).map(function(i){
return {
x: i,
y: Math.abs(offset + a*Math.sin(i/10) + b*Math.sin(i/20) + c*Math.sin(i/40) + Math.sin(i/50) + Math.sin(i/100))
}
})
}
hx.theme().plot.colors.forEach(function(col, i) {
axis.addSeries('line', {
title: 'Series ' + (i+1),
data: createData(randomSign(), randomSign(), randomSign()),
labelInterpolated: true,
markersEnabled: true,
strokeEnabled: true,
strokeColor: col,
fillEnabled: true,
fillColor: hx.color(col).alpha(0.2).toString(),
group: 'some-group'
})
})
graph.render()
.graph-example {
height: 400px;
}
[
{x: 0, y: 10},
{x: 1, y: 11},
{x: 2, y: 16},
{x: 3, y: 12}
]
[
{x: 0, y: 10, color: hx.color.graph[1]},
{x: 1, y: 11, color: hx.color.graph[2]},
{x: 2, y: 16, color: hx.color.graph[3]},
{x: 3, y: 12, color: hx.color.graph[4]}
]
new hx.BandSeries({
labelFormatters: {
'x': function(value) { return x },
'y1': hx.format.si(3),
'y2': hx.format.si(3)
}
})
[
{x: 0, y: 10},
{x: 1, y: 11},
{x: 2, y: 16},
{x: 3, y: 12}
]
[
{x: 0, y: 10, color: hx.color.graph[1]},
{x: 1, y: 11, color: hx.color.graph[2]},
{x: 2, y: 16, color: hx.color.graph[3]},
{x: 3, y: 12, color: hx.color.graph[4]}
]
new hx.BarSeries({
labelFormatters: {
'x': function(value) { return x },
'y': hx.format.si(3)
}
})
[
{x: 0, y: 10},
{x: 1, y: 11},
{x: 2, y: 16},
{x: 3, y: 12}
]
[
{x: 0, y: 10, color: hx.color.graph[1]},
{x: 1, y: 11, color: hx.color.graph[2]},
{x: 2, y: 16, color: hx.color.graph[3]},
{x: 3, y: 12, color: hx.color.graph[4]}
]
[
{x: 0, y: 10},
{x: 1, y: 11},
{x: 2, y: 16},
{x: 3, y: 12}
]
[
{x: 0, y: 10, color: hx.color.graph[1]},
{x: 1, y: 11, color: hx.color.graph[2]},
{x: 2, y: 16, color: hx.color.graph[3]},
{x: 3, y: 12, color: hx.color.graph[4]}
]
[
{x: 0, y: 10},
{x: 1, y: 11},
{x: 2, y: 16},
{x: 3, y: 12}
]
new hx.LineSeries({
labelFormatters: {
'x': function(value) { return x },
'y': hx.format.si(3)
}
})
[
{x: 0, y: 10},
{x: 1, y: 11},
{x: 2, y: 16},
{x: 3, y: 12}
]
[
{x: 0, y: 10, color: hx.color.graph[1]},
{x: 1, y: 11, color: hx.color.graph[2]},
{x: 2, y: 16, color: hx.color.graph[3]},
{x: 3, y: 12, color: hx.color.graph[4]}
]
[
{x: 0, y: 10},
{x: 1, y: 11},
{x: 2, y: 16},
{x: 3, y: 12}
]
[
{x: 0, y: 10, color: hx.color.graph[1]},
{x: 1, y: 11, color: hx.color.graph[2]},
{x: 2, y: 16, color: hx.color.graph[3]},
{x: 3, y: 12, color: hx.color.graph[4]}
]
[
{x: 0, y1: 10, y2: 16},
{x: 1, y1: 11, y2: 17},
{x: 2, y1: 16, y2: 16},
{x: 3, y1: 12, y2: 14}
]
new hx.ScatterSeries({
labelFormatters: {
'x': function(value) { return x },
'y': hx.format.si(3)
}
})
[
{x: 0, y: 10},
{x: 1, y: 11},
{x: 2, y: 16},
{x: 3, y: 12}
]
[
{x: 0, y: 10, fillColor: hx.color.graph[1], radius: 1},
{x: 1, y: 11, fillColor: hx.color.graph[2], radius: 2},
{x: 2, y: 16, fillColor: hx.color.graph[3], radius: 3},
{x: 3, y: 12, fillColor: hx.color.graph[4], radius: 4}
]
[
{x: 0, y: 10},
{x: 1, y: 11},
{x: 2, y: 16},
{x: 3, y: 12}
]
[
{x: 0, y: 10, fillColor: hx.color.graph[1], radius: 1},
{x: 1, y: 11, fillColor: hx.color.graph[2], radius: 2},
{x: 2, y: 16, fillColor: hx.color.graph[3], radius: 3},
{x: 3, y: 12, fillColor: hx.color.graph[4], radius: 4}
]
[
{x: 0, y: 10},
{x: 1, y: 11},
{x: 2, y: 16},
{x: 3, y: 12}
]
[
{x: 0, y: 10, fillColor: hx.color.graph[1], radius: 1},
{x: 1, y: 11, fillColor: hx.color.graph[2], radius: 2},
{x: 2, y: 16, fillColor: hx.color.graph[3], radius: 3},
{x: 3, y: 12, fillColor: hx.color.graph[4], radius: 4}
]
new hx.StraightLineSeries({
labelFormatters: {
'x': function(value) { return x },
'y': hx.format.si(3)
}
})
hx.Axis::addSeries
A series is defined as an object with two properties: {
type: 'line', // The series type
options: {...} // The series options
}
nthTickVisible
property. nthTickVisible
property.
{
x: {...},
y: {...},
series: [
{
type: 'line', // The series type
options: {...} // The series options
}
]
}
{
title: "Pie Chart"
segments: [
{
name: "Segment 1"
size: 10,
fillColor: hx.cycle(hx.color.graph, 0)
},
{
name: "Segment 2"
size: 10,
fillColor: hx.cycle(hx.color.graph, 1)
},
{
name: "Segment 3"
size: 80,
fillColor: hx.cycle(hx.color.graph, 2)
}
]
}
[
{
title: "Series 1"
segments: [
{
name: "Segment 1",
size: 10,
fillColor: hx.cycle(hx.color.graph, 0)
},
{
name: "Segment 2",
size: 10,
fillColor: hx.cycle(hx.color.graph, 1)
},
{
name: "Segment 3",
size: 80,
fillColor: hx.cycle(hx.color.graph, 2)
}
]
},
{
name: "Series 2"
segments: [
{
name: "Segment 1",
size: 90,
fillColor: hx.cycle(hx.color.graph, 3)
},
{
name: "Segment 2",
size: 20,
fillColor: hx.cycle(hx.color.graph, 4)
},
{
name: "Segment 3",
size: 30,
fillColor: hx.cycle(hx.color.graph, 5)
}
]
},
{
name: "Series 3"
segments: [
{
name: "Segment 1",
size: 90,
fillColor: hx.cycle(hx.color.graph, 6)
},
{
name: "Segment 2",
size: 20,
fillColor: hx.cycle(hx.color.graph, 7)
},
{
name: "Segment 3",
size: 30,
fillColor: hx.cycle(hx.color.graph, 8)
}
]
}
]
hx.Graph
prototype constructor for details on the available option var graph = new hx.Graph('#my-graph-example')
var axis = graph.addAxis()
var series = axis.addSeries('line', 'My Series')
<div id="line-series-example" class='docs-graph'></div>
var graph = new hx.Graph('#line-series-example');
var axis = graph.addAxis({
y: {
scalePaddingMax: 0.1
}
});
var series = axis.addSeries('line', { title: 'Line Series' });
series.data(hx.range(50).map(function(d){ return {x: d, y: Math.cos(d/20)}}));
graph.render();
[
{x: 0, y: 10},
{x: 1, y: 11},
{x: 2, y: 16},
{x: 3, y: 12}
]
<div id="bar-series-example" class='docs-graph'></div>
var graph = new hx.Graph('#bar-series-example')
var axis = graph.addAxis({
x: {
scaleType: 'discrete'
},
y: {
scaleType: 'linear',
scalePaddingMax: 0.1,
yMin: 0
}
});
axis.addSeries('bar', {
title: 'Bar Series',
data: hx.range(7).map(function (d) {
return {
x: d,
y: Math.cos(d/10),
color: hx.theme().plot.colors[d]
}
})
});
graph.render();
[
{x: 0, y: 10},
{x: 1, y: 11},
{x: 2, y: 16},
{x: 3, y: 12}
]
<div id="stacked-line-example" class='docs-graph'></div>
var graph = new hx.Graph('#stacked-line-example');
var axis = graph.addAxis({
y: {
scalePaddingMax: 0.1
}
});
axis.addSeries('line', {
title: 'Line Series 1',
group: 'group-1',
fillEnabled: true,
strokeColor: hx.theme().plot.colors[0],
data: hx.range(200).map(function(d){ return {x: d, y: (1 - Math.sin(d/20))}})
})
axis.addSeries('line', {
title: 'Line Series 2',
group: 'group-1',
fillEnabled: true,
strokeColor: hx.theme().plot.colors[1],
data: hx.range(200).map(function(d){ return {x: d, y: (1 - Math.sin(d/20))}})
})
graph.render()
<div id="stacked-bar-example" class='docs-graph'></div>
var graph = new hx.Graph('#stacked-bar-example');
var axis = graph.addAxis({
x: {
scaleType: 'discrete'
},
y: {
scalePaddingMax: 0.1
}
});
axis.addSeries('bar', {
title: 'Bar Series 1',
group: 'group-1',
fillColor: hx.theme().plot.colors[2],
data: hx.range(20).map(function(d){ return {x: d, y: (1 - Math.sin(d/20))}})
})
axis.addSeries('bar', {
title: 'Bar Series 2',
group: 'group-1',
fillColor: hx.theme().plot.colors[3],
data: hx.range(20).map(function(d){ return {x: d, y: (1 - Math.sin(d/20))}})
})
graph.render()
<div id="band-series-example" class='docs-graph'></div>
var graph = new hx.Graph('#band-series-example')
var axis = graph.addAxis({
y: {
min: 0,
scalePaddingMin: 0.1,
scalePaddingMax: 0.1
}
});
var series = axis.addSeries('band', {
title: 'Band Series',
data: hx.range(200).map(function(d){
return {
x: d,
y1: (1 - Math.sin(d/20)),
y2: (4+Math.sin(d/20))
}
})
});
graph.render();
[
{x: 0, y1: 10, y2: 16},
{x: 1, y1: 11, y2: 17},
{x: 2, y1: 16, y2: 16},
{x: 3, y1: 12, y2: 14}
]
<div id="scatter-series-example" class='docs-graph'></div>
var graph = new hx.Graph('#scatter-series-example')
var axis = graph.addAxis({
x: {
scalePaddingMin: 0.1,
scalePaddingMax: 0.1
},
y: {
scalePaddingMin: 0.1,
scalePaddingMax: 0.1
}
});
var series = axis.addSeries('scatter', {
title: 'Scatter Series',
data: hx.range(100).map(function(d){
return {
x: Math.pow(Math.random()-0.5, 3) * 3,
y: Math.pow(Math.random()-0.5, 3) * 3,
color: hx.cycle(hx.theme().plot.colors, d)
}
})
});
graph.render();
series = axis.addSeries('scatter', 'Series Name')
series.setData(...)
[
{x: 0, y: 10},
{x: 1, y: 11},
{x: 2, y: 16},
{x: 3, y: 12}
]
<div id="straight-series-example" class='docs-graph'></div>
var graph = new hx.Graph('#straight-series-example')
var axis = graph.addAxis({
x: {
min: 0,
max: 5
},
y: {
min: 0,
max: 5
}
});
var series = axis.addSeries('straight-line', {
title: 'Straight Line Series',
data: {x: 0, y: 2, dx: 1, dy: 0.5}
});
graph.render();
{x: 50, y: 20, dx: 1, dy: 2}
{x: 50}
{y: 70}
<div id="docs-pie-example" style="height:200px"></div>
pie = new hx.PieChart('#docs-pie-example');
pie.data({
title: "Pie Chart",
segments: [
{
name: "Segment 1",
size: 10,
fillColor: hx.cycle(hx.theme().plot.colors, 0)
},
{
name: "Segment 2",
size: 10,
fillColor: hx.cycle(hx.theme().plot.colors, 1)
},
{
name: "Segment 3",
size: 80,
fillColor: hx.cycle(hx.theme().plot.colors, 2)
}
]
});
pie.render();
new hx.PieChart('#docs-pie2-example',{
innerPadding: 0.5
});
<div id="docs-pie2-example" style="height:200px"></div>
pie = new hx.PieChart('#docs-pie2-example',{
innerPadding: 0.5
});
pie.data({
title: "Pie Chart",
segments: [
{
name: "Segment 1",
size: 10,
fillColor: hx.cycle(hx.theme().plot.colors ,0)
},
{
name: "Segment 2",
size: 10,
fillColor: hx.cycle(hx.theme().plot.colors ,1)
},
{
name: "Segment 3",
size: 80,
fillColor: hx.cycle(hx.theme().plot.colors ,2)
}
]
});
pie.render();
data = [
{
title: "Series 1",
segments: [
{
name: "Segment 1",
size: 10,
fillColor: hx.cycle(hx.theme().plot.colors, 0)
},
{
name: "Segment 2",
size: 10,
fillColor: hx.cycle(hx.theme().plot.colors, 1)
},
{
name: "Segment 3",
size: 80,
fillColor: hx.cycle(hx.theme().plot.colors, 2)
}
]
},
{
title: "Series 2",
segments: [
{
name: "Segment 1",
size: 90,
fillColor: hx.cycle(hx.theme().plot.colors, 3)
},
{
name: "Segment 2",
size: 20,
fillColor: hx.cycle(hx.theme().plot.colors, 4)
},
{
name: "Segment 3",
size: 30,
fillColor: hx.cycle(hx.theme().plot.colors, 5)
}
]
}
]
<div id="docs-pie3-example" style="height:200px"></div>
pie = new hx.PieChart('#docs-pie3-example');
pie.data([
{
title: "Series 1",
segments: [
{
name: "Segment 1",
size: 10,
fillColor: hx.cycle(hx.theme().plot.colors, 0)
},
{
name: "Segment 2",
size: 10,
fillColor: hx.cycle(hx.theme().plot.colors, 1)
},
{
name: "Segment 3",
size: 80,
fillColor: hx.cycle(hx.theme().plot.colors, 2)
}
]
},
{
title: "Series 2",
segments: [
{
name: "Segment 1",
size: 90,
fillColor: hx.cycle(hx.theme().plot.colors, 3)
},
{
name: "Segment 2",
size: 20,
fillColor: hx.cycle(hx.theme().plot.colors, 4)
},
{
name: "Segment 3",
size: 30,
fillColor: hx.cycle(hx.theme().plot.colors, 5)
}
]
}
]);
pie.render();