How to display two series via Google Chart API? - line

I can't get the two series of numbers to scale together.
Here is sample code that you can paste into...
http://code.google.com/intl/en/apis/chart/docs/chart_playground.html
cht=lxy
chs=400x300
chd=t:20,30,40|1,4,2|24,34,44|3,7,1
chds=20,40,1,4,24,44,1,7
chxr=0,20,54,2|1,0,7,1
chxt=x,y
chxs=0,ff0000,12,0,lt
1,0000ff,10,1,lt
chco=FF0000,00FF00
chdl=Apples
Oranges
chtt=Some+Values
chts=0000ff,24
Translated:
chd=t:s,e,r,i,e,s,1|s,e,r,i,e,s,2|...ors:series1,series2,...ore:series1,series2,...
chds=<series_1_min>,<series_1_max>,...
chxr=<axis_index>,<start_val>,<end_val>,<step>|...
The three varying parameters in question are:
chd=t:20,30,40|1,4,2|24,34,44|3,7,1
chds=20,40,1,4,24,44,1,7
chxr=0,20,54,2|1,0,7,1
Can anyone get this simple example working?
The chart supports multiple series but for some reason I can't scale it so that the values are displayed within scale.
Any help appreciated,
Chris

After some practice I think I needed to make the chds values the same for both sets of data. I need to play with it more but I thought I would post a working example for posterity.
cht=lxy
chs=400x300
chd=t:20,30,40|1,4,2|24,34,44,48|3,7,1,2
chds=10,50,0,10,10,50,0,10
chxr=0,10,50|1,0,10,1
chxt=x,y
chxs=0,ff0000,12,0,lt
1,0000ff,10,1,lt
chco=FF0000,00FF00
chdl=Apples
Oranges
chtt=Some+Values
chts=0000ff,24
chm=o,0000FF,0,-1,5,0|o,ff0000,1,-1,5,0
chg=10,10

Scaling can be tricky to get right.
Try using chds='a' for automatic scaling at first.

Related

Why the output of Nilearn's fetch ABIDE dataset is empty?

I want to diagonse autism and one of the best autism diagnosis datasets is ABIDE (Autism Brain Imaging Data Exchange). My final goal in this part is to have a connectivity matrix which I can use for the rest of my research. At this moment I am trying to download ABIDE dataset using Nilearn library. I use the code below as mentioned in Nilearn's documentry, but unfortunately I get an empty list from dataset.func_preproc. I don't know the reason, because it works fine for other datasets of Nilearn which I tested.
dataset = nilearn.datasets.fetch_abide_pcp(derivatives=['func_preproc', 'func_mean'])
print(dataset['func_preproc'])
and the output is:
[]
as you see , dataset['func_preproc'] is an empty list.
Does anyone have any idea about this?

Getting Steam Player's Inventory List (DOTA 2)

I read some answers from other pages and found http://steamcommunity.com/profiles//inventory/json/570/2 is how I can get the list of the player's inventory. After I went to that address, a lot of data came up. However, the problem is that the data is not presented properly. I got something like this.
{"success":true,"rgInventory":{"7905269096":{"id":"7905269096","classid":"771158876","instanceid":"782509058","amount":"1","pos":1},"7832200468":{"id":"7832200468","classid":"626495772","instanceid":"1463199080","amount":"1","pos":2},"7832199378":{"id":"7832199378","classid":"626495770","instanceid":"1463199082","amount":"1","pos":3},"7832197795":{"id":"7832197795","classid":"626495773","instanceid":"1463199083","amount":"1","pos":4},"7832127932":{"id":"7832127932","classid":"771156290","instanceid":"1463199085","amount":"1","pos":5},"7832128369":{"id":"7832128369","classid":"626495771","instanceid":"1463199086","amount":"1","pos":6},"7832128042":{"id":"7832128042","classid":"466386035","instanceid":"1463199087","amount":"1","pos":7},"7830087148":{"id":"7830087148","classid":"536091705","instanceid":"1463199088","amount":"1","pos":8},"7822471023":{"id":"7822471023","classid":"771179852","instanceid":"782509058","amount":"1","pos":9},"7797472279":{"id":"7797472279","classid":"771410455","instanceid":"782509058","amount":"1","pos":10},"7782683766":{"id":"7782683766","classid":"771181072","instanceid":"782509058","amount":"1","pos":11},"7631976019":{"id":"7631976019","classid":"771157018","instanceid":"782509058","amount":"1","pos":12}},"rgCurrency":[],"rgDescriptions":{"771158876_782509058":{"appid":"570","classid":"771158876","instanceid":"782509058","icon_url":"W_I_5GLm4wPcv9jJQ7z7tz_l_0sEIYUhRfbF4arNQkgGQGKd3kMuVpMgCwRZrh6GdUmV2uVefqzZAxsqDpH8eVO4Nb2CyAaiWsVUbt1mBngc3Zm32FdEXSSFBuQVD4Z97J3LgwOxDlDHfjc9z40ChfLKg86GW_CBqRXhIgJ1zaQ3WkhKx3uK","icon_url_large":"W_I_5GLm4wPcv9jJQ7z7tz_l_0sEIYUhRfbF4arNQkgGQGKd3kMuVpMgCwRZrh6GdUmV2uVefqzZAxsqDpH8eVO4Nb2CyAaiWsVUbt1mBngc3Zm32CZOBWOAUKgdCoUqtJKW0Q7rCFKTLTVowoQBhPHGhMOGCK_YrRq1JVAm2rA7CM1GhVgPNerBnXLi","icon_drag_url":"","name":"Ogre's
Caustic Steel Choppers","market_hash_name":"Ogre's Caustic Steel
Choppers","market_name":"Ogre's Caustic Steel
Choppers","name_color":"D2D2D2","background_color":"","type":"Uncommon
Swords","tradable":0,"marketable":0,"commodity":0,"market_tradable_restriction":"7","market_marketable_restriction":"7","descriptions":[{"type":"html","value":"Used
By: Alchemist"}
Is there any way to make it more neater so I can read the data? Or can anyone give me any ideas about how to process these data? Thanks heaps
This data is in JSON format(http://www.json.org/). It is suited to be consumed by applications. So you should write a little program that will read this data, parse it and query more elements. For example (just guessing here) that there an API where you can get an item by its ID (something like http://steamcommunity.com/items/7832200468).
The output of this program could be a list (text or HTML) of items with their names, values, rarity, etc
Edit: also this: Getting someone's Steam inventory

openpyxl: How to get multiple auto-filters on a single sheet

How can I get multiple filters on a single sheet?
A single filter is easy:
worksheet.auto_filter.ref = "A1:D4"
I can't figure out how to do multiple filters. I tried a few things like:
worksheet.auto_filter.ref = "A1:D4,A6:D9"
worksheet.auto_filter.ref = "A1:D4;A6:D9"
but noting works.
Thanks,
Ryan
The specification says that there may be only a single auto-filter per worksheet.
As long as you're happy with working with a development version you might want to look at the 2.4 development branch which has much improved filtering and sort support. I don't use filters much myself so it could use some testing and the feedback would be very helpful.
The API has changed a bit and the best documentation is in the tests:
af = AutoFilter('A1:F1')
af.add_filter_column(5, ["0"], blank=True)
ws.auto_filter = af
Found out I can use tables to implement the sort/filter functionality. And you can have multiple tables in a single sheet. Unfortunately I can't find a way to do this in openpyxl but XlsxWriter can do this very easily.
worksheet1.add_table('A1:C4')
worksheet1.add_table('F8:H15')

Chart from google api is not formatted correctly

I am using the older version of Google charts API to generate simple images.
for example: https://chart.googleapis.com/chart?chs=250x100&chd=t:265,148&cht=p3&chl=empty%20-%20%20265%20|%20with%20link%20-148
You can find the docs for api here.
The part of the link responsible for values of the chart is followed by the "t:" argument in the link.
As you see I am passing 2 values: 265 and 148 but the chart is showing them as nearly equal halves of the chart.....
Any idea why is that? Did anyone have a similar problem?
All the best,
Adam
The numbers you have supplied are both over 100, meaning that you effectively are trying to display 413%. You can create the correct graph by working out the percentage for each and using that.
In your example, you should have 64% and 36% as the values: https://chart.googleapis.com/chart?chs=250x100&chd=t:64,36&cht=p3&chl=empty%20-%20%20265%20|%20with%20link%20-148
I worked these out with the following equation:
(value / (total)) * 100

Use custom function to populate gSpreadsheet cell based on a XML/JSON response

Ok, this one has become a little tricky for me and I really need some assistance to work through it.
Problem
I have a GSpreadsheet which has a list of data, in this case Twitter usernames. Using the API of a service provider (in this case the Klout API), I would like to retrieve information about that user to populate a cell within a spreadsheet.
Based on what I can work out so far, I would need to write a custom function to do this but I have no idea where to start, how I might construct it, or if there are any examples of doing this.
Scenario
The Klout API can return either an XML or JSON response (see http://developer.klout.com/docs/read/api/API), based on the string passed. For example, the URL:
http://api.klout.com/1/users/show.xml?key=SECRET&users=thewinchesterau
would return the following XML response:
<users>
<user>
<twitter_id>17439480</twitter_id>
<twitter_screen_name>thewinchesterau</twitter_screen_name>
<score>
<kscore>56.63</kscore>
<slope>0</slope>
<description>creates content that is spread throughout their network and drives discussions.</description>
<kclass_id>10</kclass_id>
<kclass>Socializer</kclass>
<kclass_description>You are the hub of social scenes and people count on you to find out what's happening. You are quick to connect people and readily share your social savvy. Your followers appreciate your network and generosity.</kclass_description>
<kscore_description>thewinchesterau has a low level ofinfluence.</kscore_description>
<network_score>58.06</network_score>
<amplification_score>29.16</amplification_score>
<true_reach>90</true_reach>
<delta_1day>0.3</delta_1day>
<delta_5day>0.5</delta_5day>
</score>
</user>
</users>
Based on this response, I would like to be able to populate different cells with the values returned within the XML (or JSON if easier) packet.
So, for example, I would have a spreadsheet like the following which would have custom functions to go out and retrieve the value of the relevant XML element response to populate the cell:
Cell A B C D E
1 Username kscore Network score Amplification score True reach
2 thewinchester =kscore(A2) =nscore(A2) =ascore(A2) =tscore(A2)
Questions
Are there any gSpreadsheet examples you know of that use an API to pull data in from an external source?
How would one write a custom function to fetch the result from the API and populate a cell with a result of a specific element?
Any information, examples or helpers you have are greatly appreciated.
You want the importXML function, documented here. The formula you want will look something like this:
=importXML("http://api.klout.com/1/users/show.xml?key=SECRET&users=" + A1, "//users/user/score/kscore")
You could write a custom script with Google AppScript, but there's a simple solution to this similar to what Nick Johnson posted. I've tested this against the score function, but it could be easily adapted to the show endpoint with different XPath.
=importXML("http://api.klout.com/1/klout.xml?users="&A1&"&key=YOUR_API_KEY", "//users/user/kscore")
This presumes your Twitter IDs are in the A column.
Note, Google Docs limits the number of such importXML functions to 50 per spreadsheet. You could concatenate groups of 5 userids for each importXML call, effectively putting your limit to 250 a sheet.
This could also be adapted to a similar call in Excel that doesn't have that limit. Keep in mind the Klout ToS, though, using proper attribution and rate limits.