I would like to create a bar plot with two x-axis, one for the months and another for the year as shown in the picture below. I tried to find examples but couldn't find any and I don't really know where to start.
Any help is welcome.
You can call x-axis as many times you want. As illustrated in this link
you can call it multiple times. For using separate tick values, this link explains year / month tick formatting for axes. Hope these will help.
Related
I am trying to create a simple d3 chart using the library NVD3 (the information that I am using NVD3 is somewhat irrelevant), and I am struggling to create the correct x-Axis and get the correct spacing between points. I do want a scaled display of dates, so, the jump from 2014-03-01 to 2014-04-01 would be less than to 2014-03-07. So essentially what I want is the typical default time scale, except I don't want it to consider weekends and holidays as possible points, because the market is closed on these days.
I apologize in advance that I cannot post code, as the data is from a source I can't put into a fiddle or bin.
Essentially the data that I am returned is not garunteed to have the price of a stock on a valid date, and some points could be missing. Currently a single day tick on the x-axis is twice as large as the regular single day tick should be if there is data on a Monday and a Friday.
If this is confusing please tell me and I will try and reword.
If anyone has done this before or has any insight, all help is appreciated!
I'm quite confused and might need help just formulating the question, so please give good comments...
I'm trying to crossfilter some data where each data point has its own sub-dataset that I want to chart and filter on as well. Each point represents a geographic region, and associated with each point is a time series which measures a certain metric over time.
Here's what I've got so far: http://michaeldougherty.info/dcjs/
The top bar chart shows a particular value for 10 regions, and the choropleth is linked with the same data. Now, below that are two composite line charts. Each line corresponds to a region -- there are 10 lines in each graph, and each graph is measuring a different metric over time. I would like the lines to be filtered as well, so if one bar is selected, only one line will show on the line chart.
Moreover, I want to be able to filter by time on the line charts (through brushing) in addition to some other filter, so I can make queries like "filter out all regions whose line value between 9 AM and 5 PM is less than 20,000", which would also update the bar and choropleth charts.
This is where I'm lost. I'm considering scrapping DC.js for this and using crossfilter and d3.js directly because it seems so complicated, but I would love it if I'm missing something and DC.js can actually handle this. I'd also love some ideas on where to start implementing this in straight crossfilter, because I haven't fully wrapped my head around that yet either.
How does one deal with datasets within datasets?
Screenshot of the link above included for convenience:
I have data like this:
document: [{"key":"01/01/2001","values":2},
{"key":"02/01/2001","values":1},
{"key":"31/01/2001","values":2}]
I am creating an area chart with .interpolate("linear") to create the following:
The idea being to represent number of documents "created" throughout January.
However, this is kind of a misleading output as it would imply there are values throughout January, when there aren't just 2 at the start and one at the end.
My questions are:
Fundamentally is this the wrong graph to represent this data, and should a bar chart be used instead?
Can D3 add evenly spaced "zero" values for each day in January?
Is the best we can do is use .interpolate("cardinal") to produce something like:
Thanks in advance!
I think the answer from this other SO post gives a usable answer, reposting it here so that this is not a dead-end for visitors coming from Google and finding this post first (as I did).
d3 linechart - Show 0 on the y-axis without passing in all points?
I have some data which is collected for 6 days during 8:00AM to 11:00AM. I need to plot all the data on same plot one over other. The way I am doing now:
hold on
plot(y1,x1,':b*','MarkerEdgeColor','k')
plot(y2,x2,':r*','MarkerEdgeColor','k')
plot(y3,x3,':y*','MarkerEdgeColor','k')
plot(y4,x4,':g*','MarkerEdgeColor','k')
plot(y5,x5,':c*','MarkerEdgeColor','k')
plot(y6,x6,':w*','MarkerEdgeColor','k')
datetick('x','HH:MM:SS')
hold off
where x1 to x6 has y axis data and y1 to y6 have
y(i) = datenum(Year(1:5), Month(1:5), Input_Vector(1:5,2), Input_Vector(1:5,3), Input_Vector(1:5,4), Input_Vector(1:5,5));
When I plot using above, I get the image attached
But what I need to find patterns by observing them. So I need to have something one above other with x axis 8:00:00 to 11:00:00
I need something like and I got this by making DAY parameter constant date.
If you want to plot one day over another, then the method you used to make the second graph - discarding/replacing the date part of your datetime - is likely the best way to do it. It matches up nicely with the conceptual question that the graph answers, i.e.: "Is there a link between time of day and duration of journey, regardless of the day it was taken on?"
If you still want to preserve the day information, you could always perform the multiple plots with different line specs, and have the legend show which line corresponds to which day.
If the above question - finding a link between time and journey duration - is what you are trying to do, rather than plotting that specific type of graph, I would also try something like this:
Split your day into half hour or quarter hour slots and take the average of all data points in each block. This gives you a single value for each half/quarter hour span.
Plot this as a bar chart with error bars showing standard error (this can be done using bar and errorbars)
If I see anything, try fitting it with an appropriate model and check for goodness of fit. In your case this would probably be a Gaussian model, as your data kinda looks like it peaks around 9:20.
Check out this quick and dirty example that I threw together: http://zoopoetics.com/d3/irregular_layout.html
d3 is doing its job admirably, laying out the columns at irregular intervals because months are of irregular durations. As we all know, a month can last from 28 to 31 days.
Thing is, the irregular layout is unsettling to the eye. I want the columns to lay out at regular pixel intervals along the horizontal axis.
Looked all over the googles for an answer and found very little about this problem, which suggests that I may be missing something obvious.
Has anyone else been here and surmounted the problem? Thanks!
My first approach would be to use the time x axis but render the bars against a different scale of lets say 365/12 intervals.
The x scale I think should have the month name labels in the middle of each month as well as a tick at the middle:
Here is my version of your file
here