How do require ALL datapoints recorded for large datasets within a stock chart?

71 Views Asked by At

How do I ensure all data is recorded on a single amcharts3 stock chart when using fairly large datasets? Amcharts.makeChart() seems to omit values, despite setting syncDataTimestamps: true.

I have two datasets that I am comparing with the compared: true setting, much like this answer. Both datasets have datetimes in the form of strings. One dataset is significantly larger than the other. Initially I had suspected that one of the datasets was not being displayed, but after setting compareGraphBullet: round, I noticed a single bullet point, shown in this screenshot.

    var my_chart =  AmCharts.makeChart("my_chart_div", {
    type: "stock",
    theme: "light",

    dataDateFormat: "YYYY-MM-DD JJ:NN:SS:QQQ",

    categoryAxis: {
        parseDates: true,
        minPeriod: 'fff'
    },
    categoryAxesSettings: {
        minPeriod: "fff",
        groupToPeriods: ['fff', 'ss']
    },

    syncDataTimestamps: true,

    dataSets: [
        {
            title: "my_first_data thing",
            fieldMappings: [{
                fromField: "reading",
                toField: "value"
            }],
            dataProvider: data1_provider,
            categoryField: "datetime",
            compared: true
        },
        {
            title: "my_second_data thing",
            fieldMappings: [{
                fromField: "target_value",
                toField: "value"
            }],
            dataProvider: data2_provider,
            categoryField: "datetime",
            compared: true
        }
    ],

    panels: [{
        // showCategoryAxis: false,
        title: "Data set #1",
        recalculateToPercents: "never",
        stockGraphs: [{
            id: "g1",
            valueField: "value",
            compareGraphBullet: 'round',
            comparable: true,
            compareField: "value"
        }],

        stockLegend: {
        }
    }]
});

Edit: And here's a link to a codepen that seems to exhibit much the same issue.

1

There are 1 best solutions below

0
xorspark On

The issue is due to your groupToPeriods setting combined with the synchronize timestamps functionality you're using. When you set groupToPeriods, you're instructing amCharts to group data into your specified periods when the overall maxSeries is reached (from smallest to largest period in the array). Even though there are only a few points in your dataset, the synchronize timestamp method creates dummy points in order for data comparisons to work, so the visible points happen to get grouped into a single point in your screenshot and showing nothing at all in your codepen.

Your only options are to either remove groupToPeriods or disable grouping entirely by setting maxSeries to 0, but the latter impacts performance. You can find more information on how stock chart data grouping works here.