google charts: timeline: dynamic height with scalebar position - charts

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

Related

how to make horizontal padding in iOS danielgindi charts

I'm using the ios-charts library and I would like to add some horizontal padding to my line charts so that the line does not start immediately at the border of the graph.
This is my current chart:
but I would like the blue line to have some padding as shown below. The rest should remain as it is. The reference gray lines should still take the entire width as they currently do.
I found it. This "padding" is actually ruled by the chart.xAxis.axisMinimum and chart.xAxis.axisMaximum. Those values are automatically set to the data min x and max x.
So if I want a left padding I just have to set a chart.xAxis.axisMinimum
In my case, I want around 10% of the x values to be padded, so I calculate it as
// dates is an array of Date representing my x values
if let maxX = dates
.map(\.timeIntervalSince1970)
.max(),
let minX = dates
.map(\.timeIntervalSince1970)
.min() {
let spanX = maxX - minX
let padding = spanX * 0.1
let axisMinimum = minX - padding
// set the left padding
chart.xAxis.axisMinimum = axisMinimum
}

Tabelview rows not showing(because of wrong constraints) in swift

this is the cell design design img
for pic
width = height = 40, top = 15, leading = 15
here for name rose d i have given constraint
width = 60, top = 15, leading = 10
for place a bid on the request label
top = 15, leading = 5
for trip for few days label
top = 15, leading = 5, trailing >= 20
for dummy caption shoe here label
trailing = 20, leading to image = 10, top to rose d = 5 and label lines = 0
for 46 mins ago label
top and leading to dummy caption.. lable = 10, trailing >= 20
i don't want to give row fixed height.. because dummy caption label may increase..
now rows not showing in tableview.. only if i give fixed height then only showing
here where i go wrong with constraints.. so i not getting rows in tableview, please guide me
if i give bottom constraint to lowest label and if i add more text to middle label then coming like this design and constraint of middle label img
You have not set any bottom constraints, therefore the layout doesn't know how to anchor the bottom of the cell to your UI elements.
Set constraints from the lowest element to the bottom of the cell's content view, or more flexibly set greater or equal to constraints from all lower elements so you don't need to worry about the number of lines in your labels.
However, I think a better approach would be to use a single label with an attributed string to provide the colouring. This will be more flexible and ensure the spacing between words looks natural.

How to adapt crossAxisCount of GridView based on its width in Flutter?

What is the best practice to adapt the number of columns (crossAxisCount) of a GridView based on its width in Flutter?
Maybe I can better explain the intended behaviour by referencing HTML:
I create 6 boxes (e.g. DIVs) with a width of 200 px (and same height) each.
(a) If the element surrounding these boxes has a width of 400 px, it would automatically show 2 boxes per row in 3 rows.
(b) If the element surrounding these boxes has a width of 700 px, it would automatically show 3 boxes per row in 2 rows.
Use Wrap. It can put renderboxes as many as fit to a row, then wrap to the next row. (formerly a comment, but it looks like the answer!)
I do this like below. You can try..
int getItemCountPerRow(BuildContext context) {
double minTileWidth = 200; //in your case
double availableWidth = MediaQuery.of(context).size.width;
int i = availableWidth ~/ minTileWidth;
return i;
}

make bigger space for legend in echarts

I'm using echarts
this is my chart
this picture shows I lost some of my legends , so,how do I make bigger space for legends, is it possible to set more space for legends? or if it is possible to make my chart smaller how can I do?
I put
var option = {
grid: {
y: 30,
y2: 90,
},
y mean space before chart, y2 - after chart

iOS Charts Pie Chart Size

I am using iOS Charts with Swift 3.
I have a 100 x 100 PieChartView that renders the pie chart, but it's not filling the view (an NSView, to be precise). The gray box is the view and there's a large gap between the pie and the edge.
I have confirmed that the view is 100 x 100:
print(graph.frame) //<-- (25.0, 65.0, 100.0, 100.0)
So I assume there is something I need to configure in the pie chart to allow it to be the full size in the view. Here's what I've tried so far to no avail:
graph.holeRadiusPercent = 0.7
graph.transparentCircleRadiusPercent = 0
graph.legend.enabled = false
graph.chartDescription?.enabled = false
graph.minOffset = 0
Any ideas?
Found it! It turns out my graph was rendering the values in the pre-selection state. If I clicked on a pie segment, it would grow larger.
So by setting this property, the graph fills the available space:
ds.selectionShift = 0 //'ds' is my PieChartDataSet
I hope that helps someone else.