Highcharts Single Line series JSON date data format - json

I am trying to implement the Single Line series chart here: http://www.highcharts.com/stock/demo/basic-line
I see the JSON format for the report is as follows:
/* May 2006 */
[1147651200000,67.79],
[1147737600000,64.98],
[1147824000000,65.26],
[1147910400000,63.18],
[1147996800000,64.51],
[1148256000000,63.38],
[1148342400000,63.15],
[1148428800000,63.34],
[1148515200000,64.33],
[1148601600000,63.55],
[1148947200000,61.22],
[1149033600000,59.77],
How do I change my data format of [date, count] into the format above?
eg my format ["2013-01-01", 55],
Thanks for any light you can shed.

There is a javascript function Date.UTC which will do the conversion for you. e.g.
[Date.UTC(2013,0,1),55],
Note, the Javascript months start at 0 (for Jan), not 1.
N.B. Make sure your axis type is 'datetime'.

In PHP do this:
$timestamp = 1000 * strtotime($your_date);

Related

How to output a CSV file with fortran(separate with comma) on one line? [duplicate]

This question already has answers here:
How to write Fortran Output as CSV file?
(5 answers)
Closed 1 year ago.
I'm the beginner of Fortran.
I would like to ask you how to get CSV file.
In my case, I use this code for get output:
However, Unfortunately, after calculation, I get this result like this:
I would like to write the value at one line.
Does anyone know how to fix this problem? Or please tell me another best method how to fix it.
Thank you.
Steve's first rule of Fortran - never use list-directed output when you care about the layout.
Fortran has several features that can help you here:
The G0.d format that will accept any intrinsic datatype and format numerics in a form Excel will accept
The * infinite group repeat count that repeats the following format group as many times as is needed by the input data
The : edit descriptor that stops processing non-data-transmitting format elements
Combining these can serve you well in your quest for CSV output. For example:
implicit none
real :: x(2),y(2),rou(2)
integer :: i
x = [-1.,-1.0007]
y = [0.,0.]
rou = [-1.499337,-1.499337]
do i=1,2
write (*,'(*(G0.7,:,","))') x(i),y(i),0.0,rou(i)
end do
end
outputs:
-1.000000,.000000,.000000,-1.499337
-1.000700,.000000,.000000,-1.499337
Use a format statement. Assuming you want the number formats shown in your image
do i = 1, mx
do j = 1, my
write(99, 900) x(i,j), ",", y(i,j), ",", 0.d0, ",", rou(i,j)
end do
end do
900 format (F8.4, A, 2(E8.2,A), F8.6)
If you want the file to have a header row, write it before the do loop using a different format statement

How to use chart.js to plot line chart with x axis as time stamp in seconds

I want to use chart.js to plot a real time plot of data being received on the html webapp using websockets with the value received as Y-Axis and reception time (in secs) as X-Axis.
Well, I assume you know HTML/JavaScript/CSS, websockets, etc to use chart.js in your apps.
Here is a related post that might be of help to get you started....
Chart.js number Y-AXIS label format for many decimal places
You just have to get started somewhere, sometime!!!
Good luck.
Use the addData method.
From the documentation at http://www.chartjs.org/docs/#advanced-usage-prototype-methods
.addData( valuesArray, label )
Calling addData(valuesArray, label) on your Chart instance passing an
array of values for each dataset, along with a label for those points.
// The values array passed into addData should be one for each dataset in the chart
myLineChart.addData([40, 60], "August");
// This new data will now animate at the end of the chart.

Highcharts - add points to all series using json

I want to create dynamically updated chart of network usage / time. Number of series can change due because I don't know how many network adapters will be in the system at the moment.
I wrote a script which returns data in json format:
[{"name":"eth0_upload","data":[[1417981348000,5585.0]]},
{"name":"eth0_download","data":[[1417981348000,4258.0]]},
{"name":"lo_upload","data":[[1417981348000,960.0]]},
{"name":"lo_download","data":[[1417981348000,960.0]]}]
how can I add this points to my chart? Can I update series like series.addPoints(jsondata, ...) or is there any way to call serie by id/name (like series[eth0_upload].addPoints(jsondata[0], ...)?
You can get serie by id like here

d3.js How to not graph values outside of range?

I have a multi-bar graph with 7 different bar listings. Dates are on the x axis and decimal values are on the y axis. Some of these listings have empty strings ("") for their decimal values and they are graphed as 0.000. I don't want these to show up at all. I tried using chart.yDomain.([0, 3]); and setting the empty values to -1 and they don't show up on the graph, but the spacing between the bars is the same as if they were graphed.
I also tried not putting empty value pairs into the graph datum array, but that messed up the date sorting since not every listing has a value for each date.
Here's an example of the JSON data I am using for the graphing:
"x_data":["08\/15\/13","11\/11\/13","11\/13\/13","11\/14\/13","11\/18\/13","11\/19\/13","11\/20\/13","11\/25\/13","12\/05\/13","12\/09\/13","12\/11\/13","12\/12\/13"],
"y_data":[[["","","","","","","",0.875,"",0.41,"",""]],[["","","","","","","","",0.285,"",0.92,""]],[["",0.203,0.17,0.223,0.193,0.303,0.263,"","","","",""]],[["",0.433,0.333,0.665,0.353,0.413,0.458,"","","","",""]],[["",0.355,0.3,0.263,0.258,0.355,0.215,"","","","",""]],[["",0.195,0.43,0.243,0.28,0.44,0.4,"","","","",""]],[[1.218,"","","","","","","","","","",""]]]}
Here is a screen shot of how it looks without setting the domain:
http://i.imgur.com/TO3wwWF.png?1
Here is a screen shot of what it looks like when I do set the domain:
http://i.imgur.com/NEwgkJf.png?1
Since you haven't provided a fiddle or equivalent, it's not possible to provide a copy-and-paste answer, but a general approach would be to remove the null values from the data before creating the chart.
Since the data in your example isn't formatted exactly as D3.js expects, I'll assume you're not simply fetching it using D3's built-in request function (e.g. d3.json('url/to/data.json')) but, rather, have the data in local variable. Assuming you also want to preserve the structure above, you could do something like the following. (It's not optimized to make the logic as clear as possible.)
var cleandata = {
x_data: [],
y_data: []
};
data.y_data.forEach(function(y_value, idx){
if (y_value) {
cleandata.x_data.push(data.x_data[idx]);
cleandata.y_data.push(data.y_data[idx]);
}
})

Is there something like printf in Action Script 3?

I searched it for while but didn't find anything like printf in Action Script.
That makes it a little difficult to generate formated strings.
Printf-as is a third-party library that will handle this. Here is the GitHub repo. From the README:
printf("You can also display numbers like PI: %f, and format them to a fixed precision,
such as PI with 3 decimal places %.3f", Math.PI, Math.PI);
// outputs: " You can also display numbers like PI: 3.141592653589793,
// and format them to a fixed precision, such as PI with 3 decimal places 3.142"
It also plays well with dates:
var date : Date = new Date();
printf("Today is %d/%m/%Y", date, date, date);
think you might be looking for StringUtil.substitute()
take a look here:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/StringUtil.html#substitute
There is the Formatter classes that you could use or create custom formatters.
http://livedocs.adobe.com/flex/3/html/help.html?content=createformatters_2.html
The only function I know that prints to a standard output is trace() (debug purposes only) , which can take virtually any type of variable.
I might not have understood your question, though.