JSON and Charting

Thor

Honorary Master
Joined
Jun 5, 2014
Messages
44,236
[)roi(];18131541 said:
No worries; simple conversion of _kabal_'s approach to use of higher order functions.

This:

PHP:
function convert($v) 
    { 
      return [strtotime($v->dateTime), $v->value]; 
    }

and this:

PHP:
json_encode(array_map('convert', $json->priceTimeSeries[0]->price))

was an eye opener.

I came close I did it like this:

PHP:
$currency_history = $json->priceTimeSeries[0]->price))

I was close, but yet so far.

Thanks again this helps a lot!!!

Now the storing.

Tired me wants to just save $url and then run the loop on the stored $url
PHP:
$statement = $db->prepare("INSERT INTO `currency` (`url_contents`) VALUES (:url_contents)");
$statement->execute(array(':url_contents' => file_get_contents($url)));

Young and exciting me wants to learn joins in order to store array_map to the DB
 
Last edited:

Thor

Honorary Master
Joined
Jun 5, 2014
Messages
44,236
@driod

I fiddled!

Here is what I wanted!!!


$currency_history = json_encode($json->priceTimeSeries[0]->price);

Look!! How awesome is this!!!

2016-08-11_22-30-44.jpg

2016-08-11_22-31-01.jpg


Thank YOU kabal and thank you @[)roi(]

exceptional individuals
 

Thor

Honorary Master
Joined
Jun 5, 2014
Messages
44,236
a bit late to the game and not as pretty as _kabal_'s solution but if you're ever looking for quick graphs
https://developers.google.com/chart/

I looked at google graphs but it went over my head to much javascript I am still on the php train I need to master one at a time :p

No I'm kidding, I just like one particular graph and that is the area fill one that highcharts offers. I think it is the same one that Moneyweb useses.
 

zippy

Honorary Master
Joined
May 31, 2005
Messages
10,321
You should consider Python. Python has libraries that can be produce platform independent graphs with minimal code. Google matplotlib, numpy etc. JSON objects can be easily decoded into nympy arrays which in a few lines of code can be pushed into matplotlib to produce a graph
 

Thor

Honorary Master
Joined
Jun 5, 2014
Messages
44,236
You should consider Python. Python has libraries that can be produce platform independent graphs with minimal code. Google matplotlib, numpy etc. JSON objects can be easily decoded into nympy arrays which in a few lines of code can be pushed into matplotlib to produce a graph

In time.

I want to learn all the languages!

But first I need to learn how to think like a programmer.
 

battletoad

Expert Member
Joined
Mar 10, 2009
Messages
1,451
You should consider Python. Python has libraries that can be produce platform independent graphs with minimal code. Google matplotlib, numpy etc. JSON objects can be easily decoded into nympy arrays which in a few lines of code can be pushed into matplotlib to produce a graph

Aside of Thor's use case, Python is wonderful! I even went as far as using graphs in a numerical analytic way to compare functions when sympy "couldn't", all within python. It was fun way to cut my teeth in python, although I'm nowhere near competent yet.
 

DrJohnZoidberg

Honorary Master
Joined
Jul 24, 2006
Messages
23,995
I looked at google graphs but it went over my head to much javascript I am still on the php train I need to master one at a time :p

No I'm kidding, I just like one particular graph and that is the area fill one that highcharts offers. I think it is the same one that Moneyweb useses.

I tried both, Google Charts is not nearly as flexible as Highcharts.
 

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
In time.

I want to learn all the languages!

But first I need to learn how to think like a programmer.
Best to focus on PHP; master it first, then pick language 2.

... + it's quite easy to tie in a python script (incl. matplotlib):
PHP:
exec('python scriptname.py', $output, $return);
foreach ($output as $line) {
  print "$line";
}
 

Thor

Honorary Master
Joined
Jun 5, 2014
Messages
44,236
Indeed I am committed to "mastering" php then in to the next and next being C++ or Java as I would love to be able to write companion applications for my Web Sites. Will do AngularjS first before I move onto other platforms but that's still years from today
 

eternaloptimist

Well-Known Member
Joined
Jul 10, 2013
Messages
175
angular is js though ... no escaping js and it's insane libraries/frameworks if you want to do anything web related :twisted:
look at D3 also(js)
anyways, if you like this data visualization stuff good news is that Data Science and Analytics is on the rise
good luck
 

Thor

Honorary Master
Joined
Jun 5, 2014
Messages
44,236
angular is js though ... no escaping js and it's insane libraries/frameworks if you want to do anything web related :twisted:
look at D3 also(js)
anyways, if you like this data visualization stuff good news is that Data Science and Analytics is on the rise
good luck

I love data.

I'm more into ERPs and making sense of a companies data.

This is the first time I sat down and actually created data using the actual coding languages it's nice I love all of it.

Javascript is ugly as hell, but if I want to become a nodejs developer then I'll need to learn Javascript sometime as well.

PHP first and then I'll move into or start it incorporate more Javascript. I never likes Javascript since it's visible to the world so I always felt it best to use as little js as possible.
 

Thor

Honorary Master
Joined
Jun 5, 2014
Messages
44,236
If you love data you'll love Python because Python loves data.

I actually used a little python for a while, I implemented a bunch of ERPnext installations and it's written in python using the frappe or something framework, but to be honest I don't know, something felt wrong about that language I understand it's powerfulness being a glue language, but it just felt like a mess.

What I like about php is structure. Or at least I go put of my way to format it and use my naming conventions in such a way that it looks structured.
 
Top