Getting data for a Google Line Chart Visualization from PHP/MySQL - javascript

I'm trying to build a Google Line Chart with MySQL data and while I understand Javascript and how to get data with PHP I'm having a hard time wrapping my head around getting and/or formatting the data in the correct manner.
Right now my table looks like this
PERSON WEEK PRODUCTION
Bob 2 1
Bob 3 0
Bob 4 0
Bob 5 2
Bob 6 0
Paul 1 0
Paul 2 0
Paul 3 0
Paul 4 2
Paul 5 3
Paul 6 1
Mike 1 0
Mike 2 1
Mike 3 1
Mike 4 4
Mike 5 0
Mike 6 1
Ron 1 1
Ron 3 0
Ron 4 0
Ron 6 0
And the graph I essentially want create looks like this
I was able to make that in the Google Code Playground by manually tweaking the data to look like this
WEEK BOB PAUL MIKE RON
1 0 0 0 1
2 1 0 1 0
3 0 0 1 0
4 0 2 4 0
5 5 3 0 0
6 0 1 1 0
So my big question though is how do I do this in an automated fashion? Obviously I need to either modify my sql query to do the heavy lifting there or massage the data with PHP afterwards, but I'm as lost as a babe in the woods on how to do that. Further complicating the issue, at least in my eyes, is that in the original data set not every has all the weeks, but needs them to be created and zero'ed out in the final result set. Also while I'm showing 4 persons it could be 1 to N.
If anyone could point me in the right direction I would be eternally grateful!
UPDATE
#asgallant pointed me to this example he had written up - http://jsfiddle.net/asgallant/HkjDe/
I tried implementing the solution he presented, which can be seen here - http://thejspot.ws/qa/table.php
While the first table populates, the second table never displays. I've tracked it down to this line of code, but I'm not sure what the issue is.
var pivotedData = google.visualization.data.group(view, [0], groupColumns);
Any suggestions?

Related

Can I represent NULL for a specific bit in a byte flag?

I have a simple byte flag with two bits that represents if a person was invited to, and is attending, an online interview. Attendance is represented by two Radio selectors in a form, and could be either Yes, No, or NULL. Invited can be NULL.
bit index 0 = INVITED?
bit index 1 = ATTENDING?
7 6 5 4 3 2 1 0 bit index
=========================================================
128 64 32 16 8 4 2 1 binary notation
=========================================================
1 1 invited, attending
1 0 invited, not attending
0 1 not invited, attending
0 0 not invited, not attending
The user can change the Attending bit via radio controls in the
form. It can be Yes, No, or NULL.
The user cannot switch the Invited bit. It is set to 1 on initial
import, otherwise, it is NULL.
The Invited bit is set to 1 upon initial import into the
application. However, the Attending bit should be NULL, since there
we don't know yet if they're attending.
That's my problem!! The Attending bit is naturally 0, because the user hasn't confirmed if you are attending.
I don't know how to represent the state of "on initial import, Attendance is unconfirmed"
Can I represent a "NULL" state at bit index 1? Should I just add an additional bit to represent an unconfirmed state? Should I change my byte flag to better represent what's going on?
Something like this. I would have to remember to clear bit index 2.
bit index 0 = INVITED?
bit index 1 = ATTENDING?
bit index 2 = UNCONFIMRED ATTENDANCE?
7 6 5 4 3 2 1 0 bit index
=========================================================
128 64 32 16 8 4 2 1 binary notation
=========================================================
1 0 1 invited, not attending, attendance not established yet
0 1 1 invited, attending, attendance established

How to refresh jsgrid based in a plain text in real time?

I'm trying to create a dynamic datagrid using jsgrid based in a plain text.
I know I could use the option "editable" and use the own jsgrid tools to implement a dynamic datagrid, but this project is focused in a specific area where most of users are used to use plain text to copy and to archive the data in question, so it's mandatory to me to use plain text to keep easy to input and to output data whenever necessary.
Until now, I'm simply writing the data grid over again every time the input is changed, but obviously as the input becomes larger, more slow is this writing.
Here the link for tests: http://balaiomtg.ligaos.net/
Try this as input:
1 Zedruu the Greathearted
1 Steel Golem
1 Illusions of Grandeur
1 Pyromancer's Swath
1 Celestial Dawn
1 Gilded Drake
1 Vedalken Plotter
1 Political Trickery
1 Shifting Borders
1 Phyrexian Metamorph
1 Psychosis Crawler
1 Mirror-Sigil Sergeant
1 Yosei, the Morning Star
1 Keiga, the Tide Star
1 Consecrated Sphinx
1 Sun Titan
1 Niv-Mizzet, the Firemind
1 Numot, the Devastator
1 Eternal Dragon
1 Quicksilver Gargantuan
1 Chancellor of the Spires
1 Bogardan Hellkite
1 Iona, Shield of Emeria
1 Hinder
1 Spell Crumple
1 Forbid
1 Decree of Silence
1 Journey to Nowhere
1 Oblivion Ring
1 Detention Sphere (RTR)
1 Nevermore
1 Orim's Thunder
1 Dismantling Blow
1 Hallowed Burial
1 Terminus
1 Austere Command
1 Wild Research
1 Idyllic Tutor
1 Tezzeret the Seeker
1 Mystic Remora
1 Rhystic Study
1 Fact or Fiction
1 Future Sight
1 Aeon Chronicler
1 Sphinx's Revelation
1 Lightning Greaves
1 Whispersilk Cloak
1 Crystal Shard
1 Spreading Seas
1 Paradox Haze
1 Copy Enchantment
1 Venser the Sojourner
1 Sphere of the Suns
1 Vessel of Endless Rest
1 Darksteel Ingot
1 Coalition Relic
1 Expedition Map
1 Journeyer's Kite
1 Pilgrim's Eye
1 Solemn Simulacrum
1 Command Tower
1 Homeward Path
1 Reliquary Tower
1 Kher Keep
1 Terramorphic Expanse
1 Evolving Wilds
1 Celestial Colonnade
1 Glacial Fortress
1 Mystic Gate
1 Flooded Strand
1 Azorius Chancery
1 Hallowed Fountain
1 Battlefield Forge
1 Arid Mesa
1 Rugged Prairie
1 Boros Garrison
1 Sacred Foundry
1 Cascade Bluffs
1 Steam Vents
1 Izzet Boilerworks
1 Shivan Reef
1 Vivid Meadow
1 Vivid Crag
1 Vivid Creek
1 Tolaria West
1 Mistveil Plains
6 Island
5 Plains
3 Mountain
1 Bruna, the Fading Light*
1 Gisela, the Broken Blade
1 Knight of the White Orchid
1 Thalia's Lancers
1 Sol Ring*
1 Thran Dynamo*
1 Caged Sun
1 Hedron Archive*
1 Worn Powerstone*
1 Pearl Medallion
1 Grand Abolisher
1 Serra Avenger*
EDIT: set a larger sample to input.

Which chart (tool) I can use for drawing "cloud points" scatter with strength ties between them all?

I have big dataset with 200 items. For each math correlation value with others. Matrix 200x200.
Something like that:
item item correl
1 1 1
2 1 0.58
3 1 0.95
4 1 -0.05
1 2 0.58
2 2 1
3 2 0.42
4 2 -0.20
1 3 0.95
2 3 0.42
3 3 1
4 3 0.09
1 4 -0.05
2 4 -0.20
3 4 0.09
4 4 1
Or without duplicates:
item item correl
1 2 0.58
2 3 0.42
3 4 0.09
4 1 -0.05
1 3 0.95
2 4 -0.20
(Similar mechanism uses full text search: docs->doc->words, where we count doc weigth per word and further sort docs by words in query)
I need to draw network scatter where each point will be related by tie strength with each other. Something like gravity where points groups by correlation value
pic1
pic2
Prefer for interactions: select, zoom, sort, filter, search etc
You know tool something like this?
Thanks
Sounds like a job for D3.js
D3
Is this what you are looking for?: http://bl.ocks.org/mbostock/3887118
- https://d3js.org/

find all connected pixels on an image - javascript or PHP

I am trying to build a simple OCR system (if there is such a thing!)
I have a successful working model (90% recognition - which I call success :-P) for single characters - I am now trying to make it recognise multiple characters.
What I want to do is find all connected pixels (this system is designed for none joined up writing only)
so if I read across a 1 pixel high line i find a 'black' pixel - how would I then find every connected pixel - efficiently :-P
I could brute force it by literally looking at the pixel above, below, right and left and then looking at each of those pixels in the same manner but I am assuming there is a better methodology.
Or is it better to add every pixel to a matrix and then do comparisons on it then?
I basically want to output a multi dimensional array along the lines of:
1 1 1 1
1 1 1 1
0 1 1 0
0 1 1 0
0 1 1 0
0 1 1 0
1 1 1 1
1 1 1 1
Which would be a capital I
Javascript is what it is written in, but if someone has the method in PHP I should be able to convert (unless it has multiple libraries needed!)
Hope that is clear - any further info please ask in comments.

How to fix calculation error occuring on javascript as well c#

I am using mvc3 with c# language where I was stuck in calculation problem.Here I am using double type variables for 3 properties Qty,Cost and totalprice
Here totalprice=Qty*Cost;
I have requirement where I want to get totalprice of product without decimals. For example if qty=14.3 , cost=15. Then on java script/C# I will get total price 214.5
But I require 214.To solve this I used Math.Floor(214.5) to get 214. But when Qty=18.9 and cost=1500. Then on javascript or C# multiplication, I am getting total price=28349.999999999996, The correct result should be 28350. Please help me to get solution where I will get both result accurately
Choose according to you in c#.
-3 -2 -1 0 1 2 3
+--|------+---------+----|----+--|------+----|----+-------|-+
a b c d e
a=-2.7 b=-0.5 c=0.3 d=1.5 e=2.8
====== ====== ===== ===== =====
Floor -3 -1 0 1 2
Ceiling -2 0 1 2 3
Truncate -2 0 0 1 2
Round (ToEven) -3 0 0 2 3
Round (AwayFromZero) -3 -1 0 2 3
In javscript do like this:
var qty=qty.toFixed(1);
var cost=cost.toFixed(1);
var totalprice=Math.round(qty*cost);
you can use Math.round(); this solves your problem.
Math.round(214.5- .1);
This question already has an answer here: Javascript floating calculation error
you can use toFixed() for example: (1.2 - 1).toFixed(1) * 1 // 0.2

Categories

Resources