amcharts / amcharts5

The newest, fastest, and most advanced amCharts charting library for JavaScript and TypeScript apps.
Other
340 stars 91 forks source link

Issue handling gaps in line charts #1473

Closed hernes45 closed 3 months ago

hernes45 commented 5 months ago

Question Hi all!

I want to handle gaps in chart with random periodicity. The samples that i have can come mainly in hours but some times the sample comes after several hours or days.

If I configure the chart with connected: false and a timeunit: 'hour' it paints a Gap between the points that are separated more than one hour.

Is there any way to draw a gap only when the value is undefined??

Data of example: var data = [{ "year": "1971", "value": -0.254 }, { "year": "1972", "value": -0.254 }, { "year": "1977", "value": 0.019 }, { "year": "1978", "value": -0.063 }, { "year": "1979", "value": 0.05 }, { "year": "1980", "value": 0.077 }, { "year": "1981", "value": 0.12 }, { "year": "1982", "value": 0.011 }, { "year": "1983", "value": 0.177 }, { "year": "1984" }, { "year": "1989", "value": 0.104 }, { "year": "1990", "value": 0.255 },];

This is what I would like:

image

I've done a sample code to view the current behaviour: https://jsfiddle.net/b0r8n5js/1/

Kind regards!!

martynasma commented 5 months ago

You can set autoGapCount to a very large value, so that it never draws a gap because of a missing base interval, but only on data items with null value:

var series = chart.series.push(am5xy.SmoothedXLineSeries.new(root, {
  minBulletDistance: 10,
  connect: false,
  autoGapCount: 1000000,
  xAxis: xAxis,
  yAxis: yAxis,
  valueYField: "value",
  valueXField: "year",
  tooltip: am5.Tooltip.new(root, {
    pointerOrientation: "horizontal",
    labelText: "{valueY}"
  })
}));

Docs: https://www.amcharts.com/docs/v5/charts/xy-chart/series/line-series/#Auto_gaps_with_dates
github-actions[bot] commented 4 months ago

This issue is stale because it has been open 30 days with no activity. It will be closed in 5 days unless a new comment is added.