Shivin Agarwal
Shivin Agarwal

Reputation: 193

Amchart scatter plot with time series data

I m trying to plot a scatter graph using Amcharts library and my data is in time series. I m having a hard time to plot it,

below is my javascript code for what I have tried, so far:

var chart = AmCharts.makeChart("chartdiv", {
    "type": "xy",
 "dataProvider": [{'nj6kJemGCxKx5dTxZ4dDNW': '95.025', 'lineColor': '#00ff00', 'x_axis_value': '0:10:06'}, {'nj6kJemGCxKx5dTxZ4dDNW': '94.067', 'lineColor': '#00ff00', 'x_axis_value': '0:10:07'}, {'nj6kJemGCxKx5dTxZ4dDNW': '98.055', 'lineColor': '#00ff00', 'x_axis_value': '0:10:08'}, {'nj6kJemGCxKx5dTxZ4dDNW': '97.136', 'lineColor': '#00ff00', 'x_axis_value': '0:10:09'}, {'nj6kJemGCxKx5dTxZ4dDNW': '97.136', 'lineColor': '#00ff00', 'x_axis_value': '0:10:10'}],
    "valueAxes": [ {
        "axisAlpha": 0,
        "dashLength": 1,
        "position": "left",
        "title": "Y Axis"
    }],
    "dataDateFormat": "JJ:NN:SS",
    "graphs": [{
        "balloonText": "x:[[x]] y:[[y]]",
        "bullet": "triangleUp",
        "lineAlpha": 0,
        "xField": "x_axis_value",
        "yField": "nj6kJemGCxKx5dTxZ4dDNW",
        "lineColor": "#FF6600",
        "fillAlphas": 0
    }],
}
);

here is JSFiddle: http://jsfiddle.net/Shivin15/o3kp2dqb/

Any suggestion on what I m doing wrong ?

Thank you for your help.

Upvotes: 0

Views: 883

Answers (1)

xorspark
xorspark

Reputation: 16012

You need to specify that your x axis is datetime-based by creating a second value axis and setting its type to "date". You also need to fix your data to contain two-digit hours as single digit hours are will not work in dataDateFormat

Updated demo:

var chart = AmCharts.makeChart("chartdiv", {
  "type": "xy",
  "dataProvider": [{
    'nj6kJemGCxKx5dTxZ4dDNW': '95.025',
    'lineColor': '#00ff00',
    'x_axis_value': '00:10:06'
  }, {
    'nj6kJemGCxKx5dTxZ4dDNW': '94.067',
    'lineColor': '#00ff00',
    'x_axis_value': '00:10:07'
  }, {
    'nj6kJemGCxKx5dTxZ4dDNW': '98.055',
    'lineColor': '#00ff00',
    'x_axis_value': '00:10:08'
  }, {
    'nj6kJemGCxKx5dTxZ4dDNW': '97.136',
    'lineColor': '#00ff00',
    'x_axis_value': '00:10:09'
  }, {
    'nj6kJemGCxKx5dTxZ4dDNW': '97.136',
    'lineColor': '#00ff00',
    'x_axis_value': '00:10:10'
  }],
  "valueAxes": [{
    "axisAlpha": 0,
    "dashLength": 1,
    "position": "left",
    "title": "Y Axis"
  }, {
    "position": "bottom",
    "title": "X Axis",
    "type": "date"
  }],
  "dataDateFormat": "JJ:NN:SS",
  "graphs": [{
    "balloonText": "x:[[x]] y:[[y]]",
    "bullet": "triangleUp",
    "lineAlpha": 0,
    "xField": "x_axis_value",
    "yField": "nj6kJemGCxKx5dTxZ4dDNW",
    "lineColor": "#FF6600",
    "fillAlphas": 0
  }],
});
html, body {
  width: 100%;
  height: 100%;
}

#chartdiv {
  width: 100%;
  height: 100%;
}
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/xy.js"></script>
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<div id="chartdiv"></div>

Upvotes: 1

Related Questions