Skip to content Skip to sidebar Skip to footer

Setting Dygraphs Initial Column Visibility By Series Name

I'm trying to set the initial visiblity of some dygraphs data series by column name. This is because the data comes from a CSV file with columns that may come or go, but I know tha

Solution 1:

When you call new Dygraph with the path to a CSV file as its data parameter, the call is asynchronous. So your suspicion is correct -- when you call g.indexFromSetName("writer_write_start"), the data needed to get the answer you want isn't available yet.

The best way to deal with this is by moving your setVisibility code into an initial drawCallback, like so:

<script type="text/javascript">
    g = newDygraph(
        document.getElementById("graphdiv"),  // containing div"last/test.csv",
        {
            connectSeparatedPoints: true,
            includeZero: true,
            drawCallback: function(dg, is_initial) {
                if (!is_initial) return;
                dg.setVisibility(dg.indexFromSetName("writer_write_start") - 1, 0);
            }
        }
    );
</script>

Post a Comment for "Setting Dygraphs Initial Column Visibility By Series Name"