Starting from the basic Crossfilter example, i'd like to create an alternate visualization that displays the barcharts vertically instead of horizontally. That is, essentially flip the axies of the barchart.
It's easy enough to modify the original barChart function to swap the bars in the chart. I've been able to do that with these following changes:
var width = x.range()[1],
height = y.range()[0];
Becomes
var width = x.range()[1],
height = y.range()[0];
and in the nested barPath method
path.push("M", x(d.key), ",", height, "V", y(d.value), "h9V", height);
becomes
path.push("M", 0, ",", x(d.key), "h", y(d.value), "v9H", 0);
These minor changes get the bars printed nicely, but it doesn't handle the x axis with it's ticks, nor does it handle the selection brushes. Is it possible to flip the brushes on their sides? If so, how would I go about doing that?
Thanks in advance!
An easiest way would be to rotate the "g" container of each chart by 90 in chart().
Something like this:
g = div.append("svg").attr("width", width + margin.left +
margin.right).attr("height", height + margin.top +
margin.bottom).append("g").attr("transform", "translate(" +
margin.left + "," + margin.top + ")"+ "**rotate(90)**");
Related
I want to create many rectangles. This should be done automatically. How can I do this without typing thousands of values in my code? Is there an solution?
In my code I wrote every single coordinate point (4 points of each rectangle) manually in my vector "V".
Also how to connect them. "F"
And the value of each rectangle. "C"
My code is
clc
clear all
figure;
V = [0,0;1,0;1,1;0,1;5,5;10,5;10,10;5,10;2,2;4,2;4,4;2,4];
F = [1,2,3,4;5,6,7,8;9,10,11,12];%Dieser Vektor sagt mir in welcher Reihenfolge die Punkte
C = [50;24;99];
patch('Faces',F,'Vertices',V,'FaceVertexCData',C,'FaceColor','flat','EdgeColor','none') %Befehl fürs "zeichnen"
colormap(parula)
colorbar
You can use the following function to create a random rectangle, by randomly generating an (x, y) position for the bottom left corner, and randomly generating a width and height -
function rect = createRandomRectangle(maxX, maxY, minHeight, maxHeight, minWidth, maxWidth)
bottom = maxY * rand;
left = maxX * rand;
height = minHeight + rand * (maxHeight - minHeight);
width = minWidth + rand * (maxWidth - minWidth);
rect = [
left, bottom
left, bottom + height
left + width, bottom + height
left + width, bottom
];
end
Then you just need to take care of creating your V, F, C matrices (by calling createRandomRectangle in a loop) and plotting them.
Thanks for viewing and answering.
I am using Google Charts (TimeLine) to display information from database.
But the Google Chart reference only provide setting fix height for the chart.
Whereas I would like to change chart height based on the number of rows I get from data.
So I made the code:
var graph = $('#chart_timeLine').children()[0].children[0].children[1];
$(graph).css('height',graph.scrollHeight);
$(graph).css('overflow-y','auto');
Now the chart don't have a vertical scrollbar and I am satisfied.
But I found that the scalebar, which shows the the scale of timeline chart is missing.(It is actually hiding under the chart, instead of showing up at the bottom of the chart).
So then I changed scalebar's position to absolute and set it to the bottom of my chart.
Then it is ugly because it has a height of 200px, while the scale is at the bottom of that 200px, leaving a huge blank between my chart and the scale.
Is there a fix for that?
Thank you.
Instead of messing with the internal workings of the chart, set the height based on the number of rows of data in the DataTable:
// set a padding value to cover the height of title and axis values
var paddingHeight = 40;
// set the height to be covered by the rows
var rowHeight = data.getNumberOfRows() * 15;
// set the total chart height
var chartHeight = rowHeight + paddingHeight;
and then in the Timeline's options, set the height:
height: chartHeight
I tried the answer, but it did not work for me. The way I got it to work for me was this:
// Calculate height
var rowHeight = 41;
var chartHeight = dataTable.getNumberOfRows() * rowHeight + 50;
var options = {
height: chartHeight
}
The + 1 to the getNumberOfRows() is for the X-axis text.
$.ajax({
...
success: function(jsonData){
...
var options = {
height: (jsonData.length * 40) + 80,
timeline: { colorByRowLabel: true }
};
chart.draw(dataTable, options);
}
});
As far as I can tell its:
30px height for each bar
10px padding for each group.
60px for the Series.
So for a 9 bar Group = (30 * 9) + 10 = 280px
Chart Height = 280px + 60px
If you are Grouping Rows you will need to determine if your date ranges overlap with any others in that group.
Google does this by:
Getting the Group items IN START DATE ORDER
Creating an empty array of Group Display Rows
For each Group Item:
For each Display Row
If Item fits in Row...
Add it to existing Display Row
Next
If No existing Display row found
Add New Display Row
Next
I have drawn a Line chart in D3. I am facing issue in x axis alignment.Fiddle Link
var x = d3.scale.ordinal().rangeRoundBands([0, width], .2);
x.domain(dataset.map(function(d) {
return d.qName; }));
The issue is -"points and the x-axis aren't on the same level". (there's some shift visible)).
How can i shift Q1 to intersection point of x-axis and Y axis.
Any help in this regard would be highly appreciated.
You can adjust the height by adjusting the translation of the group that contains the axis, e.g. change the value height in
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")");
You may want to try (height-20) for example.
I have two UIViews and I need to draw a rectangle (or) get the frame of the smallest rectangle outside both the UIViews. How can I get this?
You can use:
CGRect smallestRectangle = CGRectUnion(view1.frame, view2.frame);
According to the docs, this function
Returns the smallest rectangle that contains the two source rectangles.
here are some steps that should work to find the rectangle you want
find the left most origin.x... = new origin.x
find the top most origin.y... = new origin.y
find the largest (origin.x + size.width)... = new size.width
find the largest (origin.y + size.height)... = new size.height
I have a UITableView with custom cells. Inside each cell I have two UILabels - message and type. The size message label is varying and the type label should come below the message label.
Since the size of message label is varying. How can I position the y coordinate of the type label ?
#define MARGIN 5
typeLabel.frame = CGRectMake(x, messagelabel.frame.size.height + messageLabel.frame.origin.y + MARGIN ,
w , h);
Try this, if your have already set the frame for type label and want the same height width and x position
CGRect frame=type_label.frame;
frame.origin.y=messagelabel.frame.origin.y + messagelabel.frame.size.height + some_gap_if_you_want;
type_label.frame=frame;
or if you havnt set the frame try this
type_label.frame=CGRectMake(x,messagelabel.frame.origin.y + messagelabel.frame.size.height + some_gap_if_you_want,width,height);
typeLabel.frame = CGRectMake(CGRectGetMinX(messagelabel.frame),
CGRectGetMaxY(messagelabel.frame)+space,
w, h)
I find this much more readable ;)