I have created a chart using dc.js, and I havea a nice label on my Y axis. However, it is running through the number next to the ticks. How can I prevent this?
Code to create the chart:
chart
.x(d3.scale.ordinal().domain(allCodes))
.xUnits(dc.units.ordinal)
.yAxisLabel("Number of actions")
.elasticY(true)
.dimension(runDimension)
.group(openActionCountGroup, "Open")
.stack(closedActionCountGroup, "Closed")
.colors (d2acolors)
.legend(dc.legend().x(540).y(10))
.title(function(d) { return d.key + ": " + d.value; })
;
You are likely looking for the margins method.
Here is an example: http://jsfiddle.net/djmartin_umich/rRVgu/
chart
.x(d3.scale.ordinal().domain(allCodes))
.height(300)
.width(300)
.margins({left: 50, right: 30, top: 0, bottom: 40})
.xUnits(dc.units.ordinal)
.yAxisLabel("Number of actions")
.elasticY(true)
.dimension(runDimension)
.group(openActionCountGroup, "Open")
.stack(closedActionCountGroup, "Closed")
.legend(dc.legend().x(540).y(10))
.title(function(d) { return d.key + ": " + d.value; });
You can change the left margin to give more room for the ticks.
Related
I have a wrap with start alignment and it shows like this.
In my case, I do not want the free space that you see on the right to remain. I can fix this with space between alignment and it looks like this.
But in this case I don't want the last line, having 3 items, to be placed that way, if not in the way that start alignment provides me.
I implemented this by calculating spacing value:
Wrap(
spacing: _calculateSpacing(),
alignment: WrapAlignment.start,
children: tiles,
);
double _calculateSpacing() {
return _calculateSpacingWith(
width: MediaQuery.of(context).size.width,
tileWidth: _TileWidget.width,
minSpacing: 4,
);
}
double _calculateSpacingWith({
required double width,
required double tileWidth,
required double minSpacing,
}) {
// N = tilesInRow
// tileWidth * N + spacing * (N-1) = width
final tilesInRow = ((width + minSpacing) / (tileWidth + minSpacing)).floor();
if (tilesInRow <= 1) {
return 0;
}
final spacing = ((width - tileWidth * tilesInRow) / (tilesInRow - 1)).floorToDouble();
return spacing;
}
I'm using google charts and in partivular I have an area chart with many monthly data. However, as you can see in the image below, the dates on x-axis are too much close and is not possible to read them. How can i separate the dates in order to show them? Many thanks!
and this is my code:
<script type='text/javascript' src='https://www.gstatic.com/charts/loader.js'></script>;
<script type='text/javascript'>;
google.charts.load('current', {'packages':['corechart']});;
google.charts.setOnLoadCallback(drawChart2);;
function drawChart2() {;
var data = google.visualization.arrayToDataTable([;
['Time', 'Retorno'],;
for ($x = 0; $x <= count($date_array_all)-1; $x++) {
['" . $date_array_all[$x] . "', " . $equity_array_all[$x] . "], ;
}
]);;
var options = {;
chartArea: {left: 70, right:50, top: 30, bottom: 50},;
series: {;
0: { color: '#469DE4' },},;
legend: 'none',;
vAxis: {textStyle:{color: '#7F7F7F'}, baselineColor: '#CCCCCC', format: '#%', gridlines: {color: 'transparent'}},;
fontName: 'Source Sans Pro',;
hAxis: {textStyle:{color: '#7F7F7F'}}};;
var chart = new google.visualization.AreaChart(document.getElementById('chart_div2'));;
var formatter = new google.visualization.NumberFormat({pattern:'#,###%'});;
formatter.format(data, 1);;
chart.draw(data, options);;
};
</script>;
<div id='chart_div2' style='height: 450px;'></div>;
try increasing the bottom of the chart area...
chartArea: {left: 70, right:50, top: 30, bottom: 72} // <-- increase bottom here
with a discrete axis (string values on the x-axis), you also have the following options...
hAxis.minTextSpacing - Minimum horizontal spacing, in pixels, allowed between two adjacent text labels.
hAxis.showTextEvery - How many horizontal axis labels to show, where 1 means show every label, 2 means show every other label, and so on.
more control is allowed with a continuous axis (actual date objects on the x-axis)
in this case, you could build an array (hAxis.ticks) with the exact values
The smaller my screen size is, the more columns will not have values. As soon as I adjust the width of my screen manually (by dragging it larger or smaller), all the values will show up. This seems like a bug. I've attached 2 photos showing how the html shows up on adjacent cells with a value and without a value showing.
One cell showing value the next not showing value |
Before I drag the window size
getGridProps: ->
{ budgets } = #props.profile
rowHeight = headerHeight = 35
extraHeightToPreventScrollBar = 10
rowsCount = budgets?.length ? 0
columns: #getColumns()
rowGetter: (i) =>
budgetRows = #getBudgetRows()
budgetRows[i]
rowsCount: rowsCount
minHeight: rowsCount * rowHeight + headerHeight + extraHeightToPreventScrollBar
enableCellSelect: not #state.tableDisabled
onGridRowsUpdated: #handleGridRowsUpdated
getColumns: ->
cols = [{ key: 'year', name: 'Year', editable: false, width: 70 }]
for month in MONTHS
cols.push
key: month
name: month
editable: not #state.tableDisabled
formatter: FormattedCell
cols.push
key: 'total'
name: 'Total'
editable: false
formatter: FormattedCell
cols.push
key: 'trash'
name: ''
editable: false
formatter: getTrashCan #removeBudget, #state.tableDisabled
width: 50
cols
getBudgetRows: ->
{ budgets } = #props.profile
_.map budgets, (monthlyBudgets) ->
row = { year: monthlyBudgets.year }
for month, monthIdx in MONTHS
row[month] = monthlyBudgets.budgets[monthIdx] ? '' # ReactDataGrid cannot take null, convert to ''
row.total = Util.getBudgetsTotal monthlyBudgets ? ''
row.trash = monthlyBudgets.year
row
A solution we found is to add minColumnWidth: 10 to the gridProps
I've been trying for days to create charts with an intelligent range, that differs when the data in the google spreadsheet is updated. However i succeeded doing so, i can't get the .setOption aspect to work. I want for example, a title, description etc with the chart. But this is not the main issue since i can insert there by hand.
More important however is the range name, because there isn't when i use the script. So, within the chart it is not possible to see what each column represents, and i really want to fix that. I tried to use the .setNamedRange() aspects, but that is not working.
Someone who can help me with that?
function check() {
var sheet = SpreadsheetApp.getActiveSheet();
var end = sheet.getLastRow();
var start = (end - 5);
var endnew = (end - 4);
var startnew = (end - 6);
if(sheet.getCharts().length == 0){
Logger.log("Er is geen grafiek");
var chartBuilder = sheet.newChart()
.asColumnChart().setStacked()
.addRange(sheet.getRange("A" + startnew + ":" + "A" + endnew)) // should have a name
.addRange(sheet.getRange("B" + startnew + ":" + "B" + endnew)) // should have a name
.addRange(sheet.getRange("E" + startnew + ":" + "E" + endnew)) //should have a name
.setOption('title', 'Effectief gebruik kantoorruimte') //not working
.setPosition(10, 10, 0, 0)
var chart = chartBuilder.build();
sheet.insertChart(chart);
}
else{
Logger.log("Er is wel een grafiek");
var charts = sheet.getCharts();
for (var i in charts) {
var chart = charts[i];
var ranges = chart.getRanges();
var builder = chart.modify();
for (var j in ranges) {
var range = ranges[j];
builder.removeRange(range);
builder
.addRange(sheet.getRange("A" + (start) + ":" + "A" + end)) //should have a name
.addRange(sheet.getRange("B" + (start) + ":" + "B" + end)) //should have a name
.addRange(sheet.getRange("E" + (start) + ":" + "E" + end)) // should have a name
.setOption('title', 'Effectief gebruik kantoorruimte')
.build();
sheet.updateChart(builder.build());
}
}
}
}
I'm assuming that this code is the issue?
builder
.addRange(sheet.getRange("A" + (start) + ":" + "A" + end))
Maybe try using the JavaScript toString() method to make sure that your text formula is working.
.addRange(sheet.getRange("A" + start.toString() + ":" + "A" + end.toString()))
There is a different format that you can use:
getRange(row, column, numRows, numColumns)
So, it would be:
getRange(start, 1, 1, numColumns)
That starts on row "start" in column A. It gets one row of data, and how ever many number of columns.
I have this code working...
myScroller.scrollTo(0, -654, 200);
I also have this working....
myScroller.scrollToElement("#p4", "1s");
Is there a way to add offset to the #id, like scrollToElement("#p4" + 100, "1s")?
No you can't.
myScroller.scrollToElement("#p4", "1s");
Because first parameter should be the CSS selector of a DOM element. Therefore can you use "#p4" + 100 for applying CSS rules? If your answer is YES then YOU CAN else YOU CANNOT.
If you wanted to scroll to next element after particular time what you can do is try with nth-child() CSS property with a appropriate timeout and incremental flag. Something like this (Assume your elements are inside a parent DIV element which have id myDiv)
var incre = 0;
function customScrollToElement(){
myScroller.scrollToElement("#myDiv:nth-child(" + incre + ")", 10);
incre ++;
}
setTimeout(function(){
customScrollToElement();
},100);
You can do it with some calculation by first using jQuery to get the element's position relative to their parent.
var left = -1 * ( $('#p4').position().left + 100 ),
top = -1 * ( $('#p4').position().top );
myScroller.scrollTo(left, top, 1000);
That will scroll 100 pixels right of the element