Vertical Line Chart

A demo of amCharts 4, the previous version. For a new project, start from the amCharts 5 demos.

Any axis in any direction

Any axis can go in any direction. So, to have a vertical date-based line chart, we just need to set chart's xAxis to value axis, and yAxis to date axis.

More about axes on an XY chart

Axis ranges

Any axis can contain vertical bands or guide lines added, with an optional label, to indicate certain ranges or points in the chart.

More about axis ranges and guides

Dashed lines

Making a dashed line is easy: just use its strokeDasharray property.

Vertical zoom

The chart can be made to zoom vertically - both by the scrollbar and cursor.

To make the cursor zoom vertically (instead of horizontally), simply set its behavior to "zoomY".

More about cursor behavior

Open in:

Code

JavaScript

// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end

// Create chart instance
var chart = am4core.create("chartdiv", am4charts.XYChart);

// Add data
chart.data = [{
    "date": "2013-11-30",
    "value": 104
}, {
    "date": "2013-12-01",
    "value": 108
}, {
    "date": "2013-12-02",
    "value": 103
}, {
    "date": "2013-12-03",
    "value": 105
}, {
    "date": "2013-12-04",
    "value": 136
}, {
    "date": "2013-12-05",
    "value": 138
}, {
    "date": "2013-12-06",
    "value": 113
}, {
    "date": "2013-12-07",
    "value": 131
}, {
    "date": "2013-12-08",
    "value": 114
}, {
    "date": "2013-12-09",
    "value": 124
}];

// Create axes
var dateAxis = chart.yAxes.push(new am4charts.DateAxis());
dateAxis.renderer.inversed = true;

// Create value axis
var valueAxis = chart.xAxes.push(new am4charts.ValueAxis());

// Create series
var series1 = chart.series.push(new am4charts.LineSeries());
series1.dataFields.valueX = "value";
series1.dataFields.dateY = "date";
series1.strokeWidth = 3;
series1.strokeDasharray = 4;
series1.bullets.push(new am4charts.CircleBullet());
series1.tooltipText = "{valueX.value}";

// Add chart cursor
chart.cursor = new am4charts.XYCursor();
chart.cursor.behavior = "zoomY";

// Add scrollbar
chart.scrollbarY = new am4core.Scrollbar();

// Create ranges
var range = valueAxis.axisRanges.create();
range.value = 0;
range.endValue = 120;
range.axisFill.fill = chart.colors.getIndex(2);
range.axisFill.fillOpacity = 0.2;

var range2 = valueAxis.axisRanges.create();
range2.value = 120;
range2.endValue = 200;
range2.axisFill.fill = chart.colors.getIndex(5);
range2.axisFill.fillOpacity = 0.2;

HTML

<div id="chartdiv"></div>

CSS

#chartdiv {
  width: 100%;
  height: 500px;
}

Resources

https://cdn.amcharts.com/lib/4/core.js
https://cdn.amcharts.com/lib/4/charts.js
https://cdn.amcharts.com/lib/4/themes/animated.js

All in one page

<!-- Resources -->
<script src="https://cdn.amcharts.com/lib/4/core.js"></script>
<script src="https://cdn.amcharts.com/lib/4/charts.js"></script>
<script src="https://cdn.amcharts.com/lib/4/themes/animated.js"></script>

<!-- Chart code -->
<script>
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end

// Create chart instance
var chart = am4core.create("chartdiv", am4charts.XYChart);

// Add data
chart.data = [{
    "date": "2013-11-30",
    "value": 104
}, {
    "date": "2013-12-01",
    "value": 108
}, {
    "date": "2013-12-02",
    "value": 103
}, {
    "date": "2013-12-03",
    "value": 105
}, {
    "date": "2013-12-04",
    "value": 136
}, {
    "date": "2013-12-05",
    "value": 138
}, {
    "date": "2013-12-06",
    "value": 113
}, {
    "date": "2013-12-07",
    "value": 131
}, {
    "date": "2013-12-08",
    "value": 114
}, {
    "date": "2013-12-09",
    "value": 124
}];

// Create axes
var dateAxis = chart.yAxes.push(new am4charts.DateAxis());
dateAxis.renderer.inversed = true;

// Create value axis
var valueAxis = chart.xAxes.push(new am4charts.ValueAxis());

// Create series
var series1 = chart.series.push(new am4charts.LineSeries());
series1.dataFields.valueX = "value";
series1.dataFields.dateY = "date";
series1.strokeWidth = 3;
series1.strokeDasharray = 4;
series1.bullets.push(new am4charts.CircleBullet());
series1.tooltipText = "{valueX.value}";

// Add chart cursor
chart.cursor = new am4charts.XYCursor();
chart.cursor.behavior = "zoomY";

// Add scrollbar
chart.scrollbarY = new am4core.Scrollbar();

// Create ranges
var range = valueAxis.axisRanges.create();
range.value = 0;
range.endValue = 120;
range.axisFill.fill = chart.colors.getIndex(2);
range.axisFill.fillOpacity = 0.2;

var range2 = valueAxis.axisRanges.create();
range2.value = 120;
range2.endValue = 200;
range2.axisFill.fill = chart.colors.getIndex(5);
range2.axisFill.fillOpacity = 0.2;
</script>

<!-- HTML -->
<div id="chartdiv"></div>