Historical data using Cubism - javascript

I have been playing with Cubism for a few days now. After successfully visualizing real time data, now I'm trying to visualize historical data.
Here is my scenario:
I want to make a history page for each user with each horizon bar showing for each day of the week. Since I have data for every 10 mins the .size would be 144. So the axis should also show 12 AM to 11:59 PM. This would show data for the last week, a day at a time.
Some problems I faced:
I couldn't get the axis to show only time, it shows day and date as well. Even if it is some other day it won't matter much since I can change the start and stop within the metric definition. How can I change the axis to only show time of day in 144px?
Is it possible to do this using Cubism?

Change cubism_axisFormatDays on line 1061 on cubism.js like this and tell me if it works:
cubism_axisFormatDays = d3.time.format("%I:%M %p");

Changing the .step should actually help you to author the axis, you can also play with the .serverDelay which will also author the axis itself:
var context = cubism.context() // set the cubism context
//.serverDelay(0) // No server delay
//.clientDelay(0) // No client delay
.step((1 * (1000*60*60))) // step once ever second
.size(1440) // and make the horizon div 1440 px wide.
.stop(); //to stop the cubism from flowing like a real time cubism
//1e3 or 1 seconds
//1e4 or 10 seconds
//6e4 or 1 minute
//3e5 or 5 minutes
//36e5 or 1 hour
//864e5 or 1 day
You can also check out this post for more detail regarding .serverDelay().
Change scale default in cubism.js

Related

Highcharts multiple series yAxis autoscaling

I've just encountered a problem with highcharts autoscaling within multiple series. Pictorial explanation:
Range 12h
-> Here, my time range is 12hours, max value is 5 (yellow).
Range 16h
-> Here, when I switch to 16h time period, max value of THE SAME SERIES changes to approx. 2.5 (yellow).
How to retain the same Yaxis max value across all time ranges?
Historical data, form the moment when the chart is initialized back to 16h before, is provided by REST API endpoint, whereas current data is fetched from HTML.
EDIT:
Additionally, when I narrow down the time range, max value apperas to be way bigger, than it is in the normal time range.
Zoomed

amCharts wrong Zoom startDates and endDates

I am using amCharts for displaying stock data. I have 7 zoom levels: 1H, 1D, 1W, 1M, 3M, 1Y, MAX. For 1H, 1D, I am using a dataset which contains minute wise data. For 1W, 1M, I use a different dataset which has hour wise data. And for rest 3 levels, I have another dataset with day wise data. Now here is my problem:
When initially, I load minute wise data at default zoom level 1D, and add a listener "changed" to chart.periodSelector, after clicking on 1W button or any further zoom level button, the difference in minutes between startDate and endDate of generated event: var minsDiff = (event.endDate.getTime() - event.startDate.getTime()) / 60000 is always equal to number of minutes in 1 day (1440) instead of 7 days.
I suppose this may be because the current dataset loaded is minutes dataset with 1440 max number of datapoints. So it may be setting date range for 1 Week equal to that of 1 Day because only that much data is available. But what I want is actual date range of 1 week if I click 1W button because I want to load a different chart with different dataset (hour wise data for 1W).
I tried using listener "zoomed" of chart. But same problem persisted.
Normally out of scope periods are not visible unless you set hideOutOfScopePeriods to false. As you noticed, if a period is greater than the amount of data available then the chart will truncate the zoom to fit the data you have. Checking the predifinedPeriod property in the changed event is a surefire way to see which button was clicked, which will help in this scenario where the data doesn't necessarily encompass the entire period:
listeners: [
{
event: "changed",
method: function(eventObj) {
console.log("clicked " + eventObj.predefinedPeriod);
}
}
]

HighStock Chart don't display line for missing Y axis data

I want to display live real data in a highstock chart.
But there is no data during the weekend.
Meaning I have data on Friday evening and Monday morning.
I don't want these points to connect between them.
This is what I have:
http://jsfiddle.net/rov8zu98/1/
[1236902400000,null],
[1237161600000,13.63],
I need a discontinued line, but null - is not ok as it also inserts a point on x axis
The thing is that I want to not display that GAP, so I want to hide it.
here is a mock-up of what I have and what I want to achieve:
As you see - I want Monday to start right after Friday ends.
Again - the image is a mock-up.
Can someone help me?
You could try adding 1 null value at the same timestamp as the first value of Monday. That seems to do what you want.
/* Mar 2009 */
[1237161600000,null], // An extra null value the same time as Monday
[1237161600000,13.63],
http://jsfiddle.net/nicholasduffy/rov8zu98/2/
You can use gapSize option.
plotOptions: {
line: {
gapSize: 1
}
},

MySQL Event update on every snapped 5 min

I was using the following MySQL event to update the table with the (CURRENT_TIME)+5) every five min. however my plan is was to get the table updated with that time every full 5 min from current time:
e.g., on 12:05 it writes 12:10, on 12:10 it writes 12:15...
So I used to fire the below event at exactly 12:30:00 for example in order to get it accurate.
CREATE EVENT x_next
ON SCHEDULE EVERY 5 MINUTE
STARTS CURRENT_TIMESTAMP
DO
UPDATE data SET x_next= CONCAT(CONCAT(HOUR(CURRENT_TIME),':'),MINUTE(CURRENT_TIME)+5);
What I am looking now is to make it more accurate to make this event act like the following JSfiddle result where if the even started at any time it will update only on the next 5 min (snapped-to):
http://jsfiddle.net/v06jrobg/
Where the result should be what the event should update.
I am wondering if anyone had this experience before or any suggestions?
Try to define a start time instead of current_timestamp
CREATE EVENT x_next
ON SCHEDULE EVERY 5 MINUTE
STARTS '2014-10-08 12:00:00'
DO
UPDATE data SET x_next=
CONCAT(HOUR(DATE_ADD(Now(),INTERVAL +5 MINUTE)),':',
MINUTE(DATE_ADD(Now(),INTERVAL +5 MINUTE)));
This will start at 12:00:00 and execute every 5 minute.
I changed your update syntax a bit also. It makes sure that the hour is added with 5 minutes, in case at 16:55 , the next value is 17:00. I think this will give 17:0 and not 17:00, might have to fix a check for that. A bit hacky but it might do the trick?

Use minute(of the day) for showing hours in dc js x axis

I have minutes of a day i.e., form 0 to 1440.
Currently I am showing these minutes as it is, but how do I show it into hours.
For example:
3:AM ......... 4:AM.........5:AM
I tried several others things but no luck till now.
Here is what I am doing currently:
.x(d3.scale.linear().range(1, chartWidth).domain([1, 1440]))
And here is what I have tried:
d3.time.scale().domain([new Date(2013,0,2), new Date(2013, 0, 3)])
This show the time exactly how I want but the graph doesn't show up.
Sounds like you may not have set the .xUnits correctly. You probably want .xUnits(d3.time.hours) for what you are doing.
https://github.com/dc-js/dc.js/blob/master/web/docs/api-latest.md#xunitsxunits-function
Basically, .xUnits always has to match the scale.
This is a very common gotcha with dc.js and we'd like to eliminate the xUnits, but we don't know how to. It is used to determine the number of points/bars.

Categories