Search code examples
anychart

Trouble loading eventmarkers from csv file with anychart


I'm trying to make a graph using anygraph. It loads data from a csv file, but i am having trouble to get the eventmarkers from the same file.

I dont seem to get the mapping/source values correct for the eventMarkers.data method. My goal is to load the markers from the same csv file as the source of the graph, where 1 column will contain marker information for some dates.

Suppose i have the following csv:

date, value, optionalmarkerinfo
2021-01-01 01:00:00,2,
2021-01-01 01:00:00,3,markerinfo

and the following code:

 anychart.data.loadCsvFile("export.csv", function (data) {
           var dataTable = anychart.data.table(0, '');
        dataTable.addData(data);

        //Create table and stuff
        var chart = anychart.stock(); // (the type of graph isnt correct for this data, but its only to generally give a skelet of my setup)
        // more stuff where i create the first timelines graph

        
        // then to add a marker on each timeframe: 
       // (data will be filtered later to only show markers on specific values of dates)
       var dataSet = anychart.data.set(data);
       var mappingMarker = dataSet.mapAs({date: 0}); 
       chart.plot(1).eventMarkers().data(mappingMarker); // THIS DOESNT WORK

       // finish the drawing:
        chart.container('container');
        chart.draw();

 }

Solution

  • Unfortunately, the Stock data and mapping instance are not compatible with the event markers. You should apply the data directly as an array of objects. As a workaround, you can load a separated CSV file, preprocess it to the compatible format and apply it to event markers.