';
}
+ $options_charts['labels'] = array_keys($data_graph_by_status);
$return['chart']['validated_vs_unvalidated'] .= pie_graph(
- $data_graph_by_status,
+ array_values($data_graph_by_status),
$options_charts
);
@@ -5401,11 +5424,13 @@ function reporting_custom_render($report, $content, $type='dinamic', $pdf=0)
$data_query,
function ($carry, $item) use ($pdf) {
if ($pdf === true) {
- $carry[$item['label'].' ('.$item['value'].')'] = $item['value'];
+ $carry['labels'][] = io_safe_output($item['label']).' ('.$item['value'].')';
} else {
- $carry[$item['label']] = $item['value'];
+ $carry['labels'][] = io_safe_output($item['label']);
}
+ $carry['data'][] = $item['value'];
+
return $carry;
},
[]
@@ -5416,8 +5441,9 @@ function reporting_custom_render($report, $content, $type='dinamic', $pdf=0)
$value_query .= '
';
}
+ $options_charts['labels'] = array_keys($data_graph_by_user);
$event['chart']['by_user_validator'] .= pie_graph(
- $data_graph_by_user,
+ array_values($data_graph_by_user),
$options_charts
);
@@ -11116,7 +11143,7 @@ function reporting_get_module_detailed_event(
$data_graph_by_criticity = [];
if (empty($event['data']) === false) {
foreach ($event['data'] as $value) {
- $k = get_priority_name($value['criticity']);
+ $k = io_safe_output(get_priority_name($value['criticity']));
if (isset($data_graph_by_criticity[$k]) === true) {
$data_graph_by_criticity[$k]++;
} else {
@@ -11143,8 +11170,9 @@ function reporting_get_module_detailed_event(
$event['chart']['by_criticity'] = '
';
}
+ $options_charts['labels'] = array_keys($data_graph_by_criticity);
$event['chart']['by_criticity'] .= pie_graph(
- $data_graph_by_criticity,
+ array_values($data_graph_by_criticity),
$options_charts
);
@@ -11189,8 +11217,9 @@ function reporting_get_module_detailed_event(
$event['chart']['validated_vs_unvalidated'] = '
';
}
+ $options_charts['labels'] = array_keys($data_graph_by_status);
$event['chart']['validated_vs_unvalidated'] .= pie_graph(
- $data_graph_by_status,
+ array_values($data_graph_by_status),
$options_charts
);
diff --git a/pandora_console/include/functions_visual_map.php b/pandora_console/include/functions_visual_map.php
index ef7ea33ca7..b14290cdfb 100755
--- a/pandora_console/include/functions_visual_map.php
+++ b/pandora_console/include/functions_visual_map.php
@@ -1227,7 +1227,7 @@ function visual_map_print_item(
$module_data = get_bars_module_data(
$id_module,
- ($layoutData['type_graph'] !== 'horizontal')
+ $layoutData['type_graph']
);
$options = [];
$options['generals']['rotate'] = true;
@@ -2344,7 +2344,7 @@ function get_if_module_is_image($id_module)
}
-function get_bars_module_data($id_module)
+function get_bars_module_data($id_module, $typeGraph='horizontal')
{
// This charts is only serialize graphs.
// In other string show image no data to show.
@@ -2364,18 +2364,25 @@ function get_bars_module_data($id_module)
}
}
- $values_to_return = [];
- $index = 0;
- $color_index = 0;
- $total = 0;
-
if (!$values) {
return false;
}
+ $values_to_return = [];
foreach ($values as $val) {
$data = explode(',', $val);
- $values_to_return[$data[0]] = $data[1];
+ $values_to_return['labels'][] = io_safe_output($data[0]);
+ if ($typeGraph === 'horizontal') {
+ $values_to_return['data'][] = [
+ 'y' => io_safe_output($data[0]),
+ 'x' => $data[1],
+ ];
+ } else {
+ $values_to_return['data'][] = [
+ 'x' => io_safe_output($data[0]),
+ 'y' => $data[1],
+ ];
+ }
}
return $values_to_return;
diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php
index 0cbb2a4092..101729d233 100644
--- a/pandora_console/include/graphs/fgraph.php
+++ b/pandora_console/include/graphs/fgraph.php
@@ -398,36 +398,33 @@ function pie_graph(
return graph_nodata_image($options);
}
- // Remove the html_entities.
- $temp = [];
- foreach ($chart_data as $key => $value) {
- $temp[io_safe_output($key)] = $value;
- }
-
- $chart_data = $temp;
-
// Number max elements.
- $max_values = (isset($options['maxValues']) === true) ? $options['maxValues'] : 9;
+ $max_values = (isset($options['maxValues']) === true) ? $options['maxValues'] : 15;
if (count($chart_data) > $max_values) {
$others_str = (isset($options['otherStr']) === true) ? $options['otherStr'] : __('Others');
$chart_data_trunc = [];
$n = 1;
foreach ($chart_data as $key => $value) {
- if ($n < $max_values) {
+ if ($n <= $max_values) {
$chart_data_trunc[$key] = $value;
} else {
- if (isset($chart_data_trunc[$others_str]) === true) {
+ if (isset($options['labels'][$key]) === true) {
+ unset($options['labels'][$key]);
+ }
+
+ if (isset($chart_data_trunc[$others_str]) === false) {
$chart_data_trunc[$others_str] = 0;
}
if (empty($value) === false) {
- $chart_data_trunc[$others_str] += $value;
+ $chart_data_trunc[$others_str] += (float) $value;
}
}
$n++;
}
+ $options['labels'][$max_values] = $others_str;
$chart_data = $chart_data_trunc;
}
@@ -804,7 +801,27 @@ function get_build_setup_charts($type, $options, $data)
$dataLabel->setOffset($dataLabelOffset);
- $dataLabelFormatter = 'formatterDataLabelPie';
+ switch ($type) {
+ case 'DOUGHNUT':
+ case 'PIE':
+ $dataLabelFormatter = 'formatterDataLabelPie';
+ break;
+
+ case 'BAR':
+ if (isset($options['axis']) === true
+ && empty($options['axis']) === false
+ ) {
+ $dataLabelFormatter = 'formatterDataHorizontalBar';
+ } else {
+ $dataLabelFormatter = 'formatterDataVerticalBar';
+ }
+ break;
+
+ default:
+ // Not possible.
+ break;
+ }
+
if (isset($options['dataLabel']['formatter']) === true) {
$dataLabelFormatter = $options['dataLabel']['formatter'];
}
@@ -1047,7 +1064,12 @@ function get_build_setup_charts($type, $options, $data)
}
// Set labels.
- $chart->labels()->exchangeArray(array_keys($data));
+ if (isset($options['labels']) === true
+ && empty($options['labels']) === false
+ && is_array($options['labels']) === true
+ ) {
+ $chart->labels()->exchangeArray($options['labels']);
+ }
// Add Datasets.
$setData = $chart->createDataSet();
diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js
index 30a1e90980..8b076265c9 100644
--- a/pandora_console/include/javascript/pandora.js
+++ b/pandora_console/include/javascript/pandora.js
@@ -2202,10 +2202,41 @@ function loadPasswordConfig(id, value) {
var formatterDataLabelPie = function(value, ctx) {
let datasets = ctx.chart.data.datasets;
- console.log(datasets[0].data);
if (datasets.indexOf(ctx.dataset) === datasets.length - 1) {
let sum = datasets[0].data.reduce((a, b) => parseInt(a) + parseInt(b), 0);
let percentage = ((value * 100) / sum).toFixed(1) + "%";
return percentage;
}
};
+
+var formatterDataHorizontalBar = function(value, ctx) {
+ let datasets = ctx.chart.data.datasets;
+ if (datasets.indexOf(ctx.dataset) === datasets.length - 1) {
+ let sum = datasets[0].data.reduce(
+ (a, b) => {
+ if (a != undefined && b != undefined) {
+ return { x: parseInt(a.x) + parseInt(b.x) };
+ }
+ },
+ { x: 0 }
+ );
+ let percentage = ((value.x * 100) / sum.x).toFixed(1) + "%";
+ return percentage;
+ }
+};
+
+var formatterDataVerticalBar = function(value, ctx) {
+ let datasets = ctx.chart.data.datasets;
+ if (datasets.indexOf(ctx.dataset) === datasets.length - 1) {
+ let sum = datasets[0].data.reduce(
+ (a, b) => {
+ if (a != undefined && b != undefined) {
+ return { y: parseInt(a.y) + parseInt(b.y) };
+ }
+ },
+ { y: 0 }
+ );
+ let percentage = ((value.y * 100) / sum.y).toFixed(1) + "%";
+ return percentage;
+ }
+};
diff --git a/pandora_console/include/lib/Dashboard/Widgets/top_n.php b/pandora_console/include/lib/Dashboard/Widgets/top_n.php
index bdbffdbc54..da69efe414 100644
--- a/pandora_console/include/lib/Dashboard/Widgets/top_n.php
+++ b/pandora_console/include/lib/Dashboard/Widgets/top_n.php
@@ -444,7 +444,7 @@ class TopNWidget extends Widget
metaconsole_restore_db();
}
} else {
- $modules = @db_get_all_rows_sql(
+ $modules = db_get_all_rows_sql(
$sql,
$search_in_history_db
);
@@ -462,6 +462,7 @@ class TopNWidget extends Widget
}
$data_hbar = [];
+ $labels = [];
$valueMax = 0;
$valueMin = 0;
$booleanModulesCount = 0;
@@ -476,7 +477,12 @@ class TopNWidget extends Widget
foreach ($modules as $module) {
$module['aliasAgent'] = ui_print_truncate_text($module['aliasAgent'], 20, false, true, false);
$item_name = $module['aliasAgent'].' - '.$module['nameModule'];
- $data_hbar[io_safe_output($item_name)] = $module[$display];
+ $labels[] = io_safe_output($item_name);
+
+ $data_hbar[] = [
+ 'x' => $module[$display],
+ 'y' => io_safe_output($item_name),
+ ];
// Calculation of max-min values for show in graph.
$calc = (ceil((5 * (float) $module[$display]) / 100) + $module[$display]);
// Set of max-min values for graph.
@@ -510,6 +516,7 @@ class TopNWidget extends Widget
'grid' => ['display' => false],
],
],
+ 'labels' => $labels,
];
$output .= vbar_graph(
diff --git a/pandora_console/include/lib/Dashboard/Widgets/top_n_events_by_group.php b/pandora_console/include/lib/Dashboard/Widgets/top_n_events_by_group.php
index 04f806c15c..8c4fece94e 100644
--- a/pandora_console/include/lib/Dashboard/Widgets/top_n_events_by_group.php
+++ b/pandora_console/include/lib/Dashboard/Widgets/top_n_events_by_group.php
@@ -424,6 +424,7 @@ class TopNEventByGroupWidget extends Widget
return $output;
} else {
$data_pie = [];
+ $labels = [];
foreach ($result as $row) {
if ($row['id_agente'] == 0) {
$name = __('System');
@@ -444,7 +445,8 @@ class TopNEventByGroupWidget extends Widget
$name .= ' ('.$row['count'].')';
- $data_pie[$name] = $row['count'];
+ $labels[] = io_safe_output($name);
+ $data_pie[] = $row['count'];
}
}
@@ -480,6 +482,7 @@ class TopNEventByGroupWidget extends Widget
'position' => 'right',
'align' => 'center',
],
+ 'labels' => $labels,
]
);
}
diff --git a/pandora_console/include/lib/Dashboard/Widgets/top_n_events_by_module.php b/pandora_console/include/lib/Dashboard/Widgets/top_n_events_by_module.php
index 8af1f8440e..0adf0b7975 100644
--- a/pandora_console/include/lib/Dashboard/Widgets/top_n_events_by_module.php
+++ b/pandora_console/include/lib/Dashboard/Widgets/top_n_events_by_module.php
@@ -427,6 +427,7 @@ class TopNEventByModuleWidget extends Widget
$output .= '
';
return $output;
} else {
+ $labels = [];
$data_pie = [];
foreach ($result as $row) {
if ($row['id_agentmodule'] == 0) {
@@ -479,7 +480,8 @@ class TopNEventByModuleWidget extends Widget
);
}
- $data_pie[$event_name.' [ '.$name.' ] ('.$row['count'].')'] = $row['count'];
+ $labels[] = $event_name.' [ '.$name.' ] ('.$row['count'].')';
+ $data_pie[] = $row['count'];
}
}
@@ -515,6 +517,7 @@ class TopNEventByModuleWidget extends Widget
'position' => 'right',
'align' => 'center',
],
+ 'labels' => $labels,
]
);
}
diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/BarsGraph.php b/pandora_console/include/rest-api/models/VisualConsole/Items/BarsGraph.php
index ed49c5d5b7..2fe9d72799 100644
--- a/pandora_console/include/rest-api/models/VisualConsole/Items/BarsGraph.php
+++ b/pandora_console/include/rest-api/models/VisualConsole/Items/BarsGraph.php
@@ -241,9 +241,10 @@ final class BarsGraph extends Item
}
}
- $moduleData = \get_bars_module_data($moduleId);
+ $moduleData = \get_bars_module_data($moduleId, $typeGraph);
if ($moduleData !== false && is_array($moduleData) === true) {
- array_pop($moduleData);
+ array_pop($moduleData['labels']);
+ array_pop($moduleData['data']);
}
$waterMark = [
@@ -284,12 +285,11 @@ final class BarsGraph extends Item
}
$options = [
- 'width' => $width,
- 'height' => $height,
- 'background' => $backGroundColor,
- 'waterMark' => $waterMark,
- 'legend' => ['display' => false],
- 'scales' => [
+ 'width' => $width,
+ 'height' => $height,
+ 'waterMark' => $waterMark,
+ 'legend' => ['display' => false],
+ 'scales' => [
'x' => [
'grid' => [
'display' => true,
@@ -309,13 +309,14 @@ final class BarsGraph extends Item
],
],
],
+ 'labels' => $moduleData['labels'],
];
if ($typeGraph === 'horizontal') {
$options['axis'] = 'y';
}
- $graph = vbar_graph($moduleData, $options);
+ $graph = vbar_graph($moduleData['data'], $options);
}
// Restore connection.
diff --git a/pandora_console/operation/network/network_report.php b/pandora_console/operation/network/network_report.php
index e8b883a88f..c91e1b1ee6 100644
--- a/pandora_console/operation/network/network_report.php
+++ b/pandora_console/operation/network/network_report.php
@@ -269,6 +269,7 @@ if (!empty($main_value)) {
// Print the data and build the chart.
$table->data = [];
$chart_data = [];
+$labels = [];
$hide_filter = !empty($main_value) && ($action === 'udp' || $action === 'tcp');
foreach ($data as $item) {
$row = [];
@@ -294,19 +295,20 @@ foreach ($data as $item) {
$table->data[] = $row;
+ $labels[] = io_safe_output($item['host']);
// Build the pie graph data structure.
switch ($order_by) {
case 'pkts':
- $chart_data[$item['host']] = $item['sum_bytes'];
+ $chart_data[] = $item['sum_bytes'];
break;
case 'flows':
- $chart_data[$item['host']] = $item['sum_flows'];
+ $chart_data[] = $item['sum_flows'];
break;
case 'bytes':
default:
- $chart_data[$item['host']] = $item['sum_bytes'];
+ $chart_data[] = $item['sum_bytes'];
break;
}
}
@@ -324,6 +326,7 @@ if (empty($data)) {
'position' => 'right',
'align' => 'center',
],
+ 'labels' => $labels,
];
// Print the graph.
diff --git a/pandora_console/operation/snmpconsole/snmp_statistics.php b/pandora_console/operation/snmpconsole/snmp_statistics.php
index 502ac9b026..56109aa04c 100755
--- a/pandora_console/operation/snmpconsole/snmp_statistics.php
+++ b/pandora_console/operation/snmpconsole/snmp_statistics.php
@@ -184,7 +184,7 @@ $table_source_data->head['num'] = __('Number');
$table_source_data->data = [];
$table_source_graph_data = [];
-
+$labels = [];
foreach ($traps_generated_by_source as $trap) {
$row = [];
@@ -202,7 +202,8 @@ foreach ($traps_generated_by_source as $trap) {
$table_source_data->data[] = $row;
- $table_source_graph_data[$trap['source']] = (int) $trap['num'];
+ $labels[] = io_safe_output($trap['source']);
+ $table_source_graph_data[] = (int) $trap['num'];
}
$table_source_row['table'] = html_print_table($table_source_data, true);
@@ -219,6 +220,7 @@ if (empty($table_source_graph_data)) {
'position' => 'right',
'align' => 'center',
],
+ 'labels' => $labels,
];
$table_source_graph = pie_graph(
@@ -255,14 +257,14 @@ $table_oid_data->head['num'] = __('Number');
$table_oid_data->data = [];
$table_oid_graph_data = [];
-
+$labels = [];
foreach ($traps_generated_by_oid as $trap) {
$table_oid_data->data[] = [
'oid' => $trap['oid'],
'num' => (int) $trap['num'],
];
-
- $table_oid_graph_data[$trap['oid']] = (int) $trap['num'];
+ $labels[] = io_safe_output($trap['oid']);
+ $table_oid_graph_data[] = (int) $trap['num'];
}
$table_oid_row['table'] = html_print_table($table_oid_data, true);
@@ -279,6 +281,7 @@ if (empty($table_oid_graph_data)) {
'position' => 'right',
'align' => 'center',
],
+ 'labels' => $labels,
];
$table_oid_graph = pie_graph(