Google Charts is changing my data order - sorting

I am trying to create a simple Google Charts Column Chart using a date string as the X-axis. When I pass in an ordered hash (or array) for some reason Google Charts re-orders my data based on its own interpretation of how to sort.
Example:
[["Dec 27", 206.17], ["28", 411.09], ["29", 411.09], ["30", 411.09], ["31", 411.09], ["Jan 1", 411.09], [" 2", 411.09], [" 3", 411.09], [" 4", 411.09], [" 5", 411.09], [" 6", 411.09], [" 7", 411.09]]
Given this data, Google chart displays:
X-Axis example as displayed by google charts
Has anyone else run into and solved this? Is there a way to tell Google Charts to accept my data order without re-sorting?

Maybe you could share all the code, here the column chart keeps the sort the same as defined in the array.
google.load('visualization', '1.1', {'packages':['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
["Date", "Amount"],
["Dec 27", 206.17],
["28", 411.09],
["29", 411.09],
["30", 411.09],
["31", 411.09],
["Jan 1", 411.09],
[" 2", 411.09],
[" 3", 411.09],
[" 4", 411.09],
[" 5", 411.09],
[" 6", 411.09],
[" 7", 411.09]
]);
var options = {
title: 'My Daily Activities'
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart'));
chart.draw(data, options);
}
<script src="https://www.google.com/jsapi"></script>
<div id="chart" style="width: 900px; height: 500px;"></div>

Related

Creating Test in Jira using Rest Assured

I am new to Rest Assured and currently trying to create a JSON message for posting an issue of type TEST in Jira using Rest Assured. However, I am not able to properly create the test steps in the message. Below are the code and the message structure that I am getting.
TestStepMap teststep = new TestStepMap();
List<TestStepMap> s = new ArrayList<TestStepMap>();
for (int i=0; i<4; i++)
{
int index = i;
String step = "Step " + (i+1);
String data = "Data " + (i+1);
String result = "Result " + (i+1);
teststep.setIndex(index);
teststep.setStep(step);
teststep.setData(data);
teststep.setResult(result);
s.add(i, teststep);
}
CustomField10011Map customfield_10011 = new CustomField10011Map();
customfield_10011.setSteps(s);
This is the output that I am getting.
{
"fields": {
"project": {
"key": "RT"
},
"summary": "Sum of two numbers",
"description": "example of manual test",
"issuetype": {
"name": "Test"
},
"customfield_10007": {
"value": "Manual"
},
"customfield_10011": {
"steps": [
{
"index": 3,
"step": "Step 4",
"data": "Data 4",
"result": "Result 4"
},
{
"index": 3,
"step": "Step 4",
"data": "Data 4",
"result": "Result 4"
},
{
"index": 3,
"step": "Step 4",
"data": "Data 4",
"result": "Result 4"
},
{
"index": 3,
"step": "Step 4",
"data": "Data 4",
"result": "Result 4"
}
]
}
}
}
The test steps 1, 2 and 3 are being overwritten by the last step. How can I solve the issue? Any suggestions are highly welcome.
Thanks in advance.
You're adding the same teststep instance to list s every time.
What you want is to create and add a new TestStepMap object per iteration, otherwise you'll always be overwriting updates on that object from an earlier iteration of the loop.
List<TestStepMap> s = new ArrayList<TestStepMap>();
for (int i=0; i<4; i++)
{
int index = i;
String step = "Step " + (i+1);
String data = "Data " + (i+1);
String result = "Result " + (i+1);
TestStepMap teststep = new TestStepMap();
teststep.setIndex(index);
teststep.setStep(step);
teststep.setData(data);
teststep.setResult(result);
s.add(i, teststep);
}

Python convert Json string to for each

I'm reading a google spreadsheet with gspread using the sheet.get_all_records(), it outputs the following:
[{"name": "test 0", "name1": "test 1", "name2": "test 2", "name3": "test 3"}, {"name": "test 0", "name1": "test 1", "name2": "test 2", "name3": "test 3"}, {"name": "test 0", "name1": "test 1", "name2": "test 2", "name3": "test 3"}, {"name": "test 0", "name1": "test 1", "name2": "test 2", "name3": "test 3"}]
I like to treat each row separatly:
list_of_hashes = sheet.get_all_records()
json_obj = json.dumps(list_of_hashes)
for line in json_obj:
print (line['name'])
print (line['name1'])
i get the error
TypeError: string indices must be integers
like it's not recognizing the Json
any idea how to solve this
How about a following modification?
json.dumps() is used for retrieving a JSON object as a string. I think that in order to modify your script, there are following 2 patterns.
Pattern 1:
From :
json_obj = json.dumps(list_of_hashes)
To :
json_obj = json.loads(json.dumps(list_of_hashes))
Pattern 2:
If sheet.get_all_records() returns a JSON object, you can directly use the returned values to for loop as follows.
json_obj = sheet.get_all_records()
for line in json_obj:
print (line['name'])
print (line['name1'])
If I misunderstand your question, I'm sorry.

How to create non-hierarchical relationship circular diagram with D3.js?

I'm trying to create a diagram which shows links between nodes on the same hierarchy level but witthin different groups in a circular layout. It's basically a visualisation of keywords/tags/groups attached to objects a la Circos:
var data =
[
{
"name": "Adam",
"tags": ["tall", "blonde"]
},
{
"name": "Barbara",
"tags": ["tall", "brunette", "student", "single"]
}
];
Or, like something I'm trying to do:
var data =
[
{
"name": "Project 1",
"categories":
[
"Category A",
"Category B",
"Category C",
"Category D"
]
},
{
"name": "Project 2",
"categories":
[
"Category C",
"Category D",
"Category E"
]
},
{
"name": "Project 3",
"categories":
[
"Category A",
"Category E"
]
},
{
"name": "Project 4",
"categories":
[
"Category A",
"Category C",
"Category D",
"Category E"
]
},
{
"name": "Project 5",
"categories":
[
"Category A",
"Category B",
"Category D"
]
}
];
Each object can have a number of categories corresponding to the number of node copies appearing in the circle. Visually, it should look something like this:
Is it possible with D3.js? If so, which layout? It looks like it would be something between chord (but without values) and bundle (without hierarchy).
I'd imagine the script would need to traverse through the JSON data and find all unique categories first and then distribute and interlink nodes of each object depending on what and how many categories are attached to it. Finally, it would label each category.
Any ideas would be appreciated.

jqGrid and jqPivot 4.7: Incorrect names for pivoted columns

This sample uses jqGrid 4.6:
http://jsfiddle.net/aUDHx/1218/
As one can see, regardless of the number of aggregates, the header names are displayed correctly ("A A", "A B", etc.)
However, when I switch to version 4.7, the pivoted columns aren't named correctly when more than one aggregate is used:
http://jsfiddle.net/aUDHx/1219/
If only one aggregate is used, the headers display correctly.
Does 4.7 have a different method of specifying the header names, or is this a bug? If the latter, does an appropriate workaround exist?
This is the code for the yDimension:
yDimension: [{
dataName: 'product',
converter: function (val) {return val.replace(/\s/g, ' ');}
}],
The converter function is used to correctly format the header name. This is not required in 4.7 if you only use one aggregate, but anything more than that causes it to break.
"Gurrido" is now the new name of jqGrid.
The problem is in spaces which you use in names. jqPivot don't support currently spaces in the names. You can fix the problem by replacing the spaces to _ (underscore) for example. I described the workaround here.
By the way Gurrido jqGrid is not the only successor of free open source jqGrid with MIT licence. After starting Gurrido jqGrid some other jqGrid forks of the last free jqGrid is developing. I post my results here. I plan to publish new version probably in the current month. Another fork you can find here. One apply in the fork many changes which I make in my repository, but one make some his own changes too.
UPDATED: The problem with the labels which you described is a bug in jqGrid 4.7. By the way you don't need to use the converter in case of usage spaces in the aggregation values.
I posted the bug fix here in my jqGrid repository. You can see the results on the demo http://jsfiddle.net/OlegKi/b47ocLd7/
The demo uses the following JavaScript code
var mydata = [
{ id: "1", product: "A A", sold: "8", sold2: "8", sold3: "8", emp: "Michelle" },
{ id: "2", product: "A A", sold: "3", sold2: "8", sold3: "8", emp: "Tania" },
{ id: "6", product: "A B", sold: "1", sold2: "8", sold3: "8", emp: "Mark" },
{ id: "3", product: "A B", sold: "5", sold2: "8", sold3: "8", emp: "Tommy" },
{ id: "4", product: "B B", sold: "2", sold2: "8", sold3: "8", emp: "Dave" },
{ id: "5", product: "B B", sold: "5", sold2: "8", sold3: "8", emp: "Carol" }
];
$("#grid").jqGrid("jqPivot", mydata, {
xDimension: [
{ isGroupField: false, width: 40, dataName: "id", label: "ID" },
{ isGroupField: false, width: 80, dataName: "emp", label: "Employee" }
],
yDimension: [
{ dataName: "product" }
],
aggregates: [
{ aggregator: "sum", width: 60, member: "sold", label: "Sold" },
{ aggregator: "sum", width: 60, member: "sold2", label: "Sold 2" }
],
colTotals: true
},
{
height: "auto",
pager: "#pager",
iconSet: "fontAwesome",
resizeStop: function () {
$(this).jqGrid("setGridWidth", this.grid.newWidth, false);
},
caption: "Daily Sales"
}
);

Get the value of a key of each hash inside an array

I have got an array of hashes, for example:
[{"id" => "1", "name" => "Name 1"},
{"id" => "2", "name" => "Name 2"},
{"id" => "3", "name" => "Name 3"}]
I would like to get the value of the key "name" for each hash, similar to this:
["Name 1", "Name 2", "Name 3"]
I looked around for quite a while but couldn't find the answer I was looking for.
It's simplest to use Enumerable#map for this purpose:
array = [{"id" => "1", "name" => "Name 1"}, {"id" => "2", "name" => "Name 2"}, {"id" => "3", "name" => "Name 3"}]
array.map { |hash| hash['name'] }
# => ["Name 1", "Name 2", "Name 3"]

Resources