Last active
August 29, 2015 14:24
-
-
Save aiiddqd/6d8ac7c873c14d774a7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Проверяем наличие комментария о нарушении срока | |
$items = get_posts(array( | |
'post_type' => 'post', | |
'numberposts' => 500, | |
)); | |
//Создаем массив и помещаем туда данные комментов | |
$data = array(); | |
foreach($items as $post): setup_postdata( $post ); | |
$day = date_format(date_create($post->post_date),'Y-m-d'); | |
$week = date_format(date_create($post->post_date),'W'); | |
$month = date_format(date_create($post->post_date),'Y-m'); | |
$year = date_format(date_create($post->post_date),'Y'); | |
$term = wp_get_post_terms( | |
$post->ID, | |
'category', | |
array('fields' => 'names') | |
); | |
if($term[0]) { | |
$cat = $term[0]; | |
} else { | |
$cat = 'Отсутствует'; | |
} | |
$user = get_userdata($post->post_author); | |
$data[] = array( | |
'day' => $day, | |
'week' => $week, | |
'month'=> $month, | |
'user_id' => $post->post_author, | |
'name' => $cat, | |
'c_id' => $post->ID, | |
); | |
endforeach; | |
wp_reset_postdata(); | |
//var_dump($data); | |
//Кросстабуляция данных (свод таблицы) | |
$pivot_table = cp_array_to_pivot_table($data, $a = 'month', $head ='name'); | |
?> | |
<div id="chart_div" style="height: 555px;"></div> | |
<script type="text/javascript" src="https://www.google.com/jsapi"></script> | |
<script type="text/javascript"> | |
google.load("visualization", "1", {packages:["corechart"]}); | |
google.setOnLoadCallback(drawChart); | |
function drawChart() { | |
var data = google.visualization.arrayToDataTable(<?php echo json_encode($pivot_table)?>); | |
var options = { | |
vAxis: {minValue: 0}, | |
isStacked: true, | |
}; | |
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); | |
chart.draw(data, options); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment