Kibana - Splitting series by field names - kibana

I was hoping to find a way to split a series by field names (and not values of a particular field) in kibana
I have a data set that looks like below:
{ { date: 24/06/2021, foo: 12, bar: 20}, { date: 24/06/2021, foo: 16, bar: 20}, { date: 25/06/2021, foo: 16, bar: 20}, { date: 25/06/2021, foo: 16, bar: 20} }
I was hoping to see something like this:
Date on the x-axis and
the average of 'foo' for that date as one point and average of 'bar' as another point on a timeseries line chart. (essentially having field values of the same document as different series(es))
Is this possible?
Context: I am importing the document from a csv and the field names ('foo' and 'bar') are columns in the csv. I have managed to get what I need by adding a 'type' column on the csv and setting its values to be 'foo' and 'bar'
example:
{ { date: 24/06/2021, val: 12, type: foo}, { date: 24/06/2021, val: 20, type: bar} ... }
and splitting the series by the 'type' field, but I wanted to know if there was a way to create the chart without having to edit the csv.

I got this to work using Kibana Lens visualization. It allows me to set Y-axis with different fields from the same document

Related

ChartJs x-axis label to be in dateTime format issue: DD-MMM-YYYY, but displayed as MMM-YYYY-DD

I am having the date value to be displayed on the x-axis in the following format: DD-MMM-YYYY. When I am passing these values, I am getting the MMM-YYYY-DD format from ChartJS.
Could you please let me know how to resolve this issue?
Many thanks
Assuming your x-axis is already defined as a time cartesian axis, you can define the option time.displayFormats.day in order to see the date in the desired format.
This could look as follows:
xAxes: [{
type: 'time',
time: {
unit: 'day',
displayFormats: {
day: 'DD-MMM-YYYY'
},
tooltipFormat: 'DD-MMM-YYYY'
}
}]

JsonPath that combines fields from a complex object

I am using jsonpath_rw_ext for python currently
I am unable to come up with a path string that returns the fields I want without getting errors.
I think I can get most of what I'm describing as individual fields however I can't put then together.
json object is an array of two objects:
[
{
'id': 9707,
'rev': 16,
'fields': {
'System.AssignedTo': {
'id': 12345
'descriptor': 'some-identifier',
'displayName': 'Jeff Saremi',
},
'System.CommentCount': 7
},
{
'id': 9708,
'rev': 10,
'fields': {
'System.AssignedTo': {
'id': 56789
'descriptor': 'another-identifier',
'displayName': 'Someone Else',
},
'System.CommentCount': 2
}
]
What I want in the results is:
id (the topmost level one), fields.System.CommentCount and fields System.AssignedTo.displayName
I do not want deeper "id" levels
Here are what i have tried individually:
jp.match('$[*].id', workitems)
returns the toplevel IDs
jp.match('$..fields["System.CommentCount"]', workitems)
returns the commentcounts promptly
jp.match('$..fields..displayName', workitems)
returns the displayNames
Apparently this cannot be done not with the library I'm using.
I had to create 3 separate lists and zip then together to have one coherent resultset.

Dynamically graph points with Highcharts

How can I dynamically graph points from a table? The table has two columns dedicated to the x and y coordinates and an additional column for duration.
Example
Say I have the table shown below. The Date and Effort columns would compose the x,y coordinates (Timestamp, Effort) for a line chart. This line chart would have data-points based on cumulative totals from the Timestamp and Effort columns. The Duration column would determine how long the entry had an impact on the data-points of the line chart. So based on this table, I would want a line chart with the coordinates listed under Data-Points.
Timestamp        Effort  Duration
4/13/2016 12:13:12.15    10     100
4/13/2016 12:13:12.80    12     100
4/13/2016 12:13:13.15    30     100
4/13/2016 12:13:13.80    50     100
Data-Points:
(4/13/2016 12:13:12.15, 10)
(4/13/2016 12:13:12.80, 22)
(4/13/2016 12:13:13.15, 42)
(4/13/2016 12:13:13.80, 80)
One of the Highcharts demos shows precisely how you can accomplish this using a static HTML table: http://www.highcharts.com/demo/column-parsed.
I've created a fiddle using your sample data and plotted it as a line chart, per your requirement: http://jsfiddle.net/brightmatrix/qgvkp0t0/
Your data table would be coded similar to the following:
<table id="datatable">
<thead>
<tr>
<th>Time</th>
<th>Effort</th>
</tr>
</thead>
<tbody>
<tr>
<th>4/13/2016 12:13:12.15</th>
<td>10</td>
</tr>
<tr>
<th>4/13/2016 12:13:12.80</th>
<td>22</td>
</tr>
<tr>
<th>4/13/2016 12:13:13.15</th>
<td>42</td>
</tr>
<tr>
<th>4/13/2016 12:13:13.80</th>
<td>80</td>
</tr>
</tbody>
</table>
You would then create your chart using the following code. Note the data attribute that calls to your HTML table's ID:
$(function () {
$('#container').highcharts({
data: {
table: 'datatable'
},
chart: {
type: 'line'
},
title: {
text: 'Data extracted from a HTML table in the page'
},
xAxis: {
type: 'category'
},
yAxis: {
allowDecimals: false,
title: {
text: 'Units'
}
},
tooltip: {
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' + this.point.y;
}
}
});
});
One thing to note: without any modifications, your timestamp data would be read into your x-axis as a datetime type. This would leave you with empty points for those dates or times in between.
In my example, I explicitly set the x-axis type to category, so that there is exactly one plot on the chart for each data point.
Now, to get the x-axis labels to appear in a more readable format, you can explore the xAxis.labels.formatter attribute (http://api.highcharts.com/highcharts#xAxis.labels.formatter) and the Highcharts.dateFormat() function (http://api.highcharts.com/highcharts#Highcharts.dateFormat).
Update (July 13, 2016): I've been able to solve the original poster's requirement of adding cumulative points based on data in an HTML table, but not the removal of dates that are older than the current data point's duration. My modifications are below.
In order to take the data from an HTML table and work with it prior to plotting the chart, I used the data.columns attribute (see http://api.highcharts.com/highcharts#data.columns).
Before your chart options are declared, I wrote this code to go through the HTML table and add the content to arrays.
// read through the HTML table and calculate cumulative effort
// solution inspired by:
// 1. http://stackoverflow.com/questions/3248869/how-do-i-get-data-from-a-data-table-in-javascript
// 2. http://stackoverflow.com/questions/10057226/how-to-get-html-table-td-cell-value-by-javascript
// set the series name as the default; this is the first entry read by data.columns
var seriesTime = ['Time'];
var seriesEffort = ['Effort'];
var seriesDuration = ['Duration'];
var table = document.getElementById('datatable');
var noRows = table.rows.length;
// go through the table and assign values to the series arrays
// start with the second row (r = 1) to omit the table's header
for (var r = 1; r < noRows; r++) {
seriesTime.push(Date.parse(table.rows[r].cells[0].innerHTML));
seriesEffort.push(parseInt(table.rows[r].cells[1].innerHTML));
seriesDuration.push(parseInt(table.rows[r].cells[2].innerHTML));
}
I then use those arrays as follows:
data: {
// refer to demo link at: http://api.highcharts.com/highcharts#data.columns
columns: [
seriesTime, // categories
seriesEffort // first series
]
},
The way this works is that the first item expected in these arrays is the series name, which is why I have as the default value when the arrays are first declared.
Now, once you have the data in arrays, you would need to run through them to calculate your cumulative totals and subtract those whose duration has passed. Unfortunately, I wasn't successful on the duration piece. Here's what I wrote in my fiddle:
// next, go through the series arrays and tally up the cumulative totals based on duration
for (var t = 2; t < seriesTime.length; t++) {
seriesEffort[t]+=seriesEffort[t-1];
for (var e = 1; e < seriesEffort.length; e++) {
if (seriesTime[e] < seriesTime[t] - seriesDuration[t]) { // NOTE: this is where I'm getting stuck
seriesEffort[t]-=seriesEffort[e];
} else {
//seriesEffort[t]+=seriesEffort[e];
}
}
}
I hope this gets you closer to your solution. I apologize that I couldn't get this 100% mocked up for you.
I ended up preprocessing the data. First, I got all of the data points into the series cumulatively. Next, I updated the datetime x values with the durations. Finally, I subtracted each individual y value whose x value was less than the cumulative data point's x value.

Getting value from cells horizontally

Hi, I have an excel sheet like the one posted above. I am trying to retrieve data from this spreadsheet and insert it into a database. An example of a few entries would be,
[personnel_no: 35, name: John, Day: 01, Value: N],
[personnel_no: 35, name: John, Day: 02, Value: N],
[personnel_no: 35, name: John, Day: 03, Value: O]
I know how to create a loop that will go through the spreadsheet by rowss but i'm stumped as to how to do it by column. I've read that phpexcel has a column iterator function but im not even sure how to do that.
Unsure why you even need the column iterator for this, because all your data is tabulated by row....
$worksheet = $objPHPExcel->getActiveSheet();
foreach ($worksheet->getRowIterator() as $row) {
$rowData = $worksheet->toArray('A'.$row->getRowIndex().':AG'.$row->getRowIndex());
... var_dump($rowData);
... insert data from $rowData into the database
}
If you want to read more about iterators, take a look at 28iterator.php in /Examples

Moment throwing TypeError string.indexOf when using Backgrid

I am using backgrid to display JSON results from the backend Db. One of the fields is time in seconds from 1970 (eg. 1362578461000) when the Backbone view receives this data backgrid sends it off to moment for formating. Moment then throws a javaScript TypeError exception indicated on line 758 of Moment.js (v.2.0.0)
TypeError: string.indexOf is not a function
The column format looks like this:
var columns = [{
name: "startTime",
label: "Start Time",
editable: false,
cell: "moment"
}, {
name: "endTime",
label: "End Time",
editable: false,
cell: "moment"
}];
Putting a brakepoint in Firebug it looks like Moment thinks that the value is a integer rather then a string.
utc()moment.js (line 960)
input = 1362578461000
format = "YYYY-MM-DDTHH:mm:ssZ"
lang = undefined
And the call to makeDateFromStringAndFormat looks like this:
makeDateFromStringAndFormat()moment.js (line 758)
config = Object { _useUTC=true, _isUTC=true, _i=1362578461000, more...}
Any ideas as to what I can do to fix/get around this?
Thanks
Author of Backgrid here. There are 2 parts to your question:
Backgrid.js has only gained compatibility with moment.js 2.0.0 in 0.2.5 released yesterday.
The moment cell doesn't accept integers as input in the model because it tries to convert timezones and locales, so your model values have to be in a datetime string format that moment knows how to parse.

Resources