PauloB PauloB - 1 month ago 10
JSON Question

amCharts keep the last bullet, but not the line connect the last two

I'm using Smoothed Line Chart, and I want to keep the last bullet, but not the line, I would like to keep the bullet with no connector attached. Is this achievable without messing up the data?

please see my [jsfiddle][1]

[1]: https://jsfiddle.net/pbarros/0qj8bLo2/4/

Answer

There isn't a way to do this without making a slight modification to your data. You can specify a gapField in your graph object to point to a boolean field in your dataset that dictates whether the point will generate a gap from itself to the next point. For example:

"dataProvider": [
// ...
{
"date": "2016-09-01T00:00:00",
"value1": 78,
"value2gap": true, //disconnect this point from the next point
"value2": 47
},
{
"date": "2016-10-01T00:00:00",
"value1": 11,
"value2": 8
}],
"graphs": [{
  // ...
  "gapField": "value2gap"
}]

Demo:

var chart = AmCharts.makeChart("chartdiv", {
  "type": "serial",
  "fontFamily": "Roboto",
  "theme": "light",
  "dataProvider": [{
    "date": "2016-04-01T00:00:00",
    "value1": 236,
    "value2": 70
  }, {
    "date": "2016-05-01T00:00:00",
    "value1": 160,
    "value2": 60
  }, {
    "date": "2016-06-01T00:00:00",
    "value1": 59,
    "value2": 22
  }, {
    "date": "2016-07-01T00:00:00",
    "value1": 77,
    "value2": 32
  }, {
    "date": "2016-08-01T00:00:00",
    "value1": 48,
    "value2": 37
  }, {
    "date": "2016-09-01T00:00:00",
    "value1": 78,
    "value2gap": true,
    "value2": 47
  }, {
    "date": "2016-10-01T00:00:00",
    "value1": 11,
    "value2": 8
  }],
  "autoMargins": false,
  "marginTop": 30,
  "marginBottom": 10,
  "marginLeft": 50,
  "autoMargins": true,
  "dataDateFormat": "YYYY-MM-DD",
  "addClassNames": true,
  "legend": {
    "align": "center",
    "equalWidths": false,
    "valueAlign": "left",
    "valueText": "[[value]]",
    "valueWidth": 70,
    "autoMargins": false,
    "marginBottom": 10,
    "marginLeft": 50,
    "switchable": false,
    "markerType": "circle"

  },
  "colors": ["red"],
  "valueAxes": [{
    "id": "v2",
    "axisThickness": 2,
    "gridAlpha": 0.15,
    "axisAlpha": 0,
    "title": "Total Count",
    "titleColor": "#444d58",
    "position": "left"
      //"minMaxMultiplier": 1.10
  }],
  "balloon": {
    "borderThickness": 1,
    "shadowAlpha": 0,
    "color": "#71799c"
  },
  "graphs": [{
    "balloonText": "total count : [[value]]",
    "id": "cat2",
    "title": "total count",
    "valueField": "value2",
    "valueAxis": "v2",
    "type": "smoothedLine",
    "bullet": "round",
    "bulletSize": 8,
    "lineThickness": 3,
    "lineAlpha": 0.5,
    "bulletBorderAlpha": 1,
    "bulletAlpha": 1,
    "bulletColor": "#ffffff",
    "bulletBorderColor": "red",
    "bulletBorderThickness": 3,
    "valueAxisColor": "#444d58",
    "gapField": "value2gap"
  }],
  "chartCursor": {
    "pan": true,
    "valueLineEnabled": true,
    "valueLineBalloonEnabled": true,
    "cursorAlpha": 0.5,
    "valueLineAlpha": 0.5,
    "cursorColor": "#1895ff",
    "categoryBalloonDateFormat": 'MMM YYYY',
  },
  "categoryField": "date",
  "categoryAxis": {
    "minPeriod": "MM",
    "parseDates": true,
    "dashLength": 1,
    "dateFormats": [{
      period: 'fff',
      format: 'JJ:NN:SS'
    }, {
      period: 'ss',
      format: 'JJ:NN:SS'
    }, {
      period: 'mm',
      format: 'JJ:NN'
    }, {
      period: 'hh',
      format: 'JJ:NN'
    }, {
      period: 'DD',
      format: 'DD MMM YY'
    }, {
      period: 'WW',
      format: 'MMM DD'
    }, {
      period: 'MM',
      format: 'MMM YYYY'
    }, {
      period: 'YYYY',
      format: 'YYYY'
    }],
    "minorGridEnabled": true
  }
});
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<div id="chartdiv" style="width: 100%; height: 500px;"></div>