HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// chart type
4
var chart = anychart.line();
5
6
// chart title
7
chart.title("Line Chart DateTime Scale");
8
9
// create custom logarithmic scale
10
var logScale = anychart.scales.log();
11
logScale.minimum(1);
12
13
// apply custom scale to y scale
14
chart.yScale(logScale);
15
16
// create custom Date Time scale
17
var dateTimeScale = anychart.scales.dateTime();
18
var dateTimeTicks = dateTimeScale.ticks();
19
dateTimeTicks.interval(0, 6);
20
21
// apply Date Time scale
22
chart.xScale(dateTimeScale);
23
24
var series = chart.line([
25
{value: 1.172, x: Date.UTC(2003, 09, 14)},
26
{value: 1.916, x: Date.UTC(2004, 09, 13)},
27
{value: 5.57, x: Date.UTC(2005, 09, 13)},
28
{value: 15.0, x: Date.UTC(2006, 09, 13)},
29
{value: 144, x: Date.UTC(2007, 09, 13)}
30
]);
31
32
// adjust tooltips
33
var tooltip = series.tooltip();
34
tooltip.format(function () {
35
var value = (this.value).toFixed(0);
36
var date = new Date(this.x);
37
var options = {year: "numeric", month: "numeric", day: "numeric"};
38
var transformedDate = date.toLocaleDateString("en-US", options);
39
40
return "Value: $" + value + " mil.\n" + transformedDate ;
41
});
42
43
// adjust axis labels
44
var labels = chart.xAxis().labels();
45
labels.hAlign("center");
46
labels.width(60);
47
labels.format(function(value){
48
var date = new Date(value["tickValue"]);
49
var options = {
50
year: "numeric",
51
month: "short"
52
};
53
return date.toLocaleDateString("en-US", options);
54
});
55
56
// set container and draw chart
57
chart.container("container");
58
chart.draw();
59
});