Convert Highcharts stacked daily column from "day" to "month" view - javascript

I've googled around to be able to do this but haven't found the exact solution. Basically, I have a chart with daily data, and I was wondering if there is a way to dynamically convert the chart to a "month" view? I'm trying to see if I can achieve this without making a separate request to my RESTful API to return back grouped data.
Here is a js fiddle: http://jsfiddle.net/qenE8/1/
My goal is to have a dropdown with "Day" and "Month" views. Thanks in advance for your help.
My current object for the xAxis property is this:
xAxis: {
"type": "datetime",
"minTickInterval": 86400000,
dateTimeLabelFormats: {
day: '%m/%d/%y' // mm/dd/yy
}
}

You can use update() function on axis, and modify your tickInterval from day to month.
http://api.highcharts.com/highcharts#Axis.update()

Related

Plotting data on x axis in Highstock

I am currently trying to plot some data which I receive via a HTTP request. The issue that I am having is that the x-axis doesn't plot the timestamp correctly because it it's in Unix format. I've read some other similar question on SO such as: Example One
The issue is that I'm not passing an object but directly an Unix time data. When hovering the graph, you can see that the x-axis doesn't display the date and hour correctly.
Here is a fiddle with my current graph: Graph Fiddle
Since you actually have datetime values, showing them using category is sort of a hack, and would also not show gaps between points correctly if they are not evenly spaced.
Instead you could merge your two arrays into pairs and then supply it to the series as proper X-Y values for a datetime axis. You also have to multiply your datetime values by 1000 to get milliseconds, which Highcharts expects.
For example (JSFiddle), merging:
dataArray.push(selectedData);
timeDataArray.push(selectedTime);
var mergedArray = timeDataArray.map(function(e, i) {
return [e*1000, dataArray[i]];
});
And axis and series:
xAxis: {
type: 'datetime'
},
series: [{
name: 'AAPL',
data: mergedArray
}]

Highcharttable.js date format x-axis

I am using highchartTable to create my chart. I am feeding the x-Axis on highchartTable with dates and this is how it currently displays
I would like to format the x-axis in such a way that it only show 'Month year', then 'year' when the result set gets bigger.
Someone suggested I do it like:
$('#hidden-highchart-table').bind('highchartTable.beforeRender', function (event, highChartConfig) {
highChartConfig.xAxis.type = 'datetime',
highChartConfig.xAxis.dateTimeLabelFormats = { month: '%b \'%y',year: '%Y'}
}).highchartTable();
But this still does not work.
Instead of setting type of axis through highChartConfig object, use data-graph-xaxis-type attribute in table tag. Take a look at the example below.
Example:
http://jsfiddle.net/m8h5oo76/

Morris.js xKey adding nonsense values

I have been struggling with this issue for an hour, and I can't figure out why Morris chart put some kind of time values into the X axe.
First of all, my JSON is the following:
{"data":[{"date":"2015-06-08","payed":"18.08","to_pay":"18.08"},
{"date":"2015-06-11","payed":"70.24","to_pay":"108.24"}]}
And I'm creating the chart this way:
var json = JSON.parse(response);
Morris.Line({
element: 'recebimentos-chart',
data: json.data,
xkey: 'date',
ykeys: ['to_pay', 'payed'],
labels: ['To pay', 'Payed'],
gridTextColor: '#000',
lineColors: ['#EA8A67', '#22aa22'],
});
And now the problem: why in god's heaven is the X axe writing the values that the image shows?
As you can see in my JSON there's two different dates. If I only have one date (no matter which one) the chart works good (it output in the X axe the date value), for example:
{"data":[{"date":"2015-06-11","payed":"18.08","to_pay":"18.08"},
{"date":"2015-06-11","payed":"70.24","to_pay":"108.24"}]}
EDIT 1: While trying in JSFiddle I found out that the problem is the width of the chart. With a small width the chart presents the dates correctly, with a large width it presents hours (??)
The problem is that I need to present a large chart..
Try this :
http://jsfiddle.net/z97z2Lam/1/
Their doc says about the xLabels property:
Sets the x axis labelling interval. By default the interval will be automatically computed. The following are valid interval strings:
"decade"
"year"
"month"
"week"
"day"
"hour"
"30min"
"15min"
"10min"
"5min"
"minute"
"30sec"
"15sec"
"10sec"
"5sec"
"second"

Highcharts - Stacked column data series

Im working with stacked column using Highcharts.
The data series im constructing is similar to this
series: [{
name: 'Apples',
data: [['2014-01-01',5], ['2014-01-02',3], ['2014-01-04',2], ['2014-01-05',7], ['2014-01-06',8]]
}, {
name: 'Oranges',
data: [['2014-01-01',3], ['2014-01-02',7], ['2014-01-04',9], ['2014-01-05',11], ['2014-01-06',19]]
}, {
name: 'Grapes',
data: [['2014-01-01',15], ['2014-01-02',23], ['2014-01-03',12], ['2014-01-05',17], ['2014-01-06',18]]
}]
http://jsfiddle.net/emgq47px/
If you take a closer look at the data, im missing 2014-01-04 data for Apples but instead the data is stacked on 2014-01-03.
One way of solving this would be to prepopulate categories and follow the same order for inserting my y values but that wont be a good way to solve as i may deal with large data sets down the line.
Any tips to head in the right direction is greatly appreciated.
UPDATE:
I'm populating my x and y co-ordinates with values from database. Database gives me date in (YYYY-mm-dd) format. So i'm converting that string to epoch time using strtotime function in PHP strtotime($res[0])
But then when I populate draw the highchart, i see wrong dates. I checked with online available epoch converters and it looks like conversion is right but i still cant figure out whats wrong here.
Even the x axis ticks seems to be slightly off.
Many thanks for your suggestions.
http://jsfiddle.net/emgq47px/3/
RESOLVED:
I had to multiply epoch time with 1000. This works.
Original answer: HighCharts - timeseries chart - irregular datetime interval on xAxis
Probably the best way is to use a datetime axis. This allows highcharts to know the data contains dates, and it can sort out the axis properly.
xAxis: {
lineWidth: 2,
type: 'datetime'
},
Once you do this, you need to supply valid date times in your data like this:
data: [[Date.UTC(2014, 0, 1),5],
[Date.UTC(2014, 0, 2),3],
[Date.UTC(2014, 0, 4),2],
[Date.UTC(2014, 0, 5),7],
[Date.UTC(2014, 0, 6),8]]
Note, months go from 0 to 11, not 1 to 12, so zero is January.
http://jsfiddle.net/0ofLx86d/
The problem is that you are marking x-axis type is category
xAxis: {
lineWidth: 2,
type: 'category'
},
So when you assign data data: [['2014-01-01',5], ['2014-01-02',3], like this to it then the first value is considered as category so when you assign ['2014-01-03',12] as last then it replaces previous one ['2014-01-04',12]. You can test it by keeping first two as 03 and last one as 04, then it will take 04 and not show 03.
Solution
Replace
type: 'category' to 'datetime'
and date to epoch time
data: [[1388534400000,5], [1388620800000,3], [1388793600000,2], [1388880000000,7]]
You can use custom function for label if you want to display date on x-axis in different format or use Date.UTC
Demo

Highcharts datetime axis, how to disable time part (show only dates)?

My chart is displaying data day-by-day (user and system sent SMS/Newsletters). So time part is not relevant and unnecessary. Here is an example: http://jsfiddle.net/uaxZP/1/ where time "12:00" is displayed.
How can I force Highcharts to never display the time part in a "datetime" axis?
EDIT: Highcharts will display dates w/wo times based on chart or screen size. I've updated jsfiddle removing some data and now it's displaying also time parts.
You can intercept the x-axis label function and change it's output. In my example, I've changed it to render short dates:
http://jsfiddle.net/uaxZP/3/
{ xAxis:
labels: {
formatter: function() {
return Highcharts.dateFormat("%b %e", this.value);
}
}
}
The xAxis.labels.formatter property allows control over this. You also may notice I'm using Highcharts.dateFormat, which is a utility function for rendering dates. This is not mandatory, but it's a nice built in feature. Documentation on the xAxis formatter is here:
http://www.highcharts.com/ref/#xAxis-labels--formatter
The easiest way to do is using "minTickInterval"
xAxis: {
minTickInterval: 24 * 3600 * 1000
}
http://api.highcharts.com/highcharts#xAxis.minTickInterval

Categories