def _combine_graph_data(graphs):
    """
    Concatenate data series from multiple graphs into a single series

    Returns
    -------
    val
        List of the form [(x_0, [y_00, y_01, ...]), (x_1, ...)]
        where the y-values are obtained by concatenating the data
        series. When some of the graphs do not have data for a given x-value,
        the missing data is indicated by None values.
    n_series
        Number of data series in output. Equal to the sum of n_series
        of the input graphs.

    """

    all_data = {}
    n_series = sum(graph.n_series if graph.n_series else 1
                   for graph in graphs)

    template = [None]*n_series
    pos = 0

    for graph in graphs:
        series = graph.get_data()
        for k, v in series:
            prev = all_data.get(k, template)
            if graph.scalar_series:
                v = [v]
            all_data[k] = prev[:pos] + v + prev[pos+graph.n_series:]
        pos += graph.n_series

    val = list(all_data.items())
    val.sort()

    return val, n_series