} else {
                        $t_metrics[3][$t_ptr] += $t_data[$t][$t_status];
                    }
                }
            }
        }
    } else {
        $i = 0;
        foreach ($t_view_status as $t_status => $t_label) {
            if (isset($t_data[$t][$t_status])) {
                $t_metrics[++$i][$t_ptr] = $t_data[$t][$t_status];
            } else {
                $t_metrics[++$i][$t_ptr] = 0;
            }
        }
    }
    if ($f_show_as_table) {
        echo '<tr class="row-' . ($t_ptr % 2 + 1) . '"><td>' . $t_ptr . ' (' . date($t_date_format, $t_metrics[0][$t_ptr]) . ')' . '</td>';
        for ($i = 1; $i <= $t_label_count; $i++) {
            echo '<td>' . $t_metrics[$i][$t_ptr] . '</td>';
        }
        echo '</tr>';
    }
}
if ($f_show_as_table) {
    echo '</table>';
    html_body_end();
    html_end();
} else {
    graph_bydate($t_metrics, $t_labels, lang_get('by_status'), $f_width, $f_width * $t_ar);
}
    html_body_begin();
    echo '<table class="width100"><tr><td></td>';
    foreach ($t_category as $t_cat) {
        echo '<th>' . $t_cat . '</th>';
    }
    echo '</tr>';
    for ($t_ptr = 0; $t_ptr < $t_bin_count; $t_ptr++) {
        echo '<tr class="row-' . ($t_ptr % 2 + 1) . '"><td>' . $t_ptr . ' (' . date($t_date_format, $t_marker[$t_ptr]) . ')' . '</td>';
        foreach ($t_category as $t_cat) {
            echo '<td>' . (isset($t_data[$t_ptr][$t_cat]) ? $t_data[$t_ptr][$t_cat] : 0) . '</td>';
        }
        echo '</tr>';
    }
    echo '</table>';
    html_body_end();
    html_end();
} else {
    # reverse the array and reorder the data, if necessary
    $t_metrics = array();
    for ($t_ptr = 0; $t_ptr < $t_bin_count; $t_ptr++) {
        $j = $t_bin_count - $t_ptr - 1;
        $t_metrics[0][$t_ptr] = $t_marker[$j];
        $i = 0;
        foreach ($t_category as $t_cat) {
            $t_metrics[++$i][$t_ptr] = isset($t_data[$j][$t_cat]) ? $t_data[$j][$t_cat] : 0;
        }
    }
    array_unshift($t_category, '');
    # add placeholder
    graph_bydate($t_metrics, $t_category, lang_get('by_category'), $f_width, $f_width * $t_ar);
}