Duplicated Numbers on Google Charts Vertical Axis - google-visualization

I was working on a bugfix with Google visualizations for a combo (column/line) chart when one of the axes went strange and started repeating numbers ( ie: 1, 1, 2, 2 instead of 1, 2, 3, 4). Please see the image below
(source: rackcdn.com)
Here are the chart option settings:
// Instantiate and draw our chart, passing in some options.
var frequency_by_day_options = {
vAxes: [
{format:'#,###', title:"Call Volume"},
{format: '#%', title:'Missed Call Rate',
viewWindow:{
max:1,
}}
],
legend: {position: 'none'},
chartArea: { height:'60%', width:'60%'},
width: 800,
height: 350,
backgroundColor: 'transparent',
bar: { groupWidth: '90%'},
isStacked: true,
seriesType: 'bars',
series: {0: {type:'bar', targetAxisIndex:0}, 1: {type:'line', targetAxisIndex:1},},
colors: ['blue', 'green'],
animation:{
duration: 1000,
easing: 'out',},
};
I have no idea what's going on here. Even when I comment out all of the vAxis options I still observe this behavior. Any ideas on what i'm doing wrong? This is driving me nuts :)

I was facing same issue when we have less number of boxes (let say 1 or 2). I resolved it with maxValue option.
Just add maxValue = 4 option in your vaxis. It will add 5 (0 to 4) gridlines at all times. If your maxValue is more that 4, it will adjust automatically.
Mine is working fine with options (title : 'No of boxes', format : '#', minValue:0, maxValue :4). minValue = 0 will not allow negatives as its no of boxes.

I am going to guess that the left-side vAxis is not 4, but actually 2. The 5 labels are 0, 0.5, 1, 1.5, 2.
Since you have format set as "#,###" it will not show decimals. If you change it to "#,###.#" then it will show 0, 0.5, 1, 1.5, 2.
There are a dozen ways to solve it, but the easiest may be to make sure that your axis values are only whole number values with a javascript function like this:
// Take the Max/Min of all data values in all graphs
var totalMax = 3;
var totalMin = -1;
// Figure out the largest number (positive or negative)
var biggestNumber = Math.max(Math.abs(totalMax),Math.abs(totalMin));
// Round to an exponent of 10 appropriate for the biggest number
var roundingExp = Math.floor(Math.log(biggestNumber) / Math.LN10);
var roundingDec = Math.pow(10,roundingExp);
// Round your max and min to the nearest exponent of 10
var newMax = Math.ceil(totalMax/roundingDec)*roundingDec;
var newMin = Math.floor(totalMin/roundingDec)*roundingDec;
// Determine the range of your values
var range = newMax - newMin;
// Calculate the best factor for number of gridlines (2-5 gridlines)
// If the range of numbers divided by 2 or 5 is a whole number, use it
for (var i = 2; i <= 5; ++i) {
if ( Math.round(range/i) = range/i) {
var gridlines = i
}
}

Related

IFS has mismatched range sizes. Expected row count: 1. column count: 1. Actual row count: 1000, column count: 1

My formula is as follows:
=ARRAYFORMULA(IFS(AND(H2:H >= -B39, H2:H <= B40), 100, H2:H > B37, 0))
However this line keeps throwing the error:
IFS has mismatched range sizes. Expected row count: 1. column count: 1. Actual row count: 1000, column count: 1.
Any idea how to fix this?
I have similar formulaes like this one that works:
=ARRAYFORMULA(IFS(F2:F <= 0, 100, F2:F >= B19, 0, true, (B19 - F2:F) / B19 * 100))
Not sure what I'm doing so differently with the first formula that would cause the issue.
AND is not supported under ARRAYFORMULA
=ARRAYFORMULA(IFS((H2:H >= -B39)*(H2:H <= B40), 100, H2:H > B37, 0))
and IFS is in some cases not suited for ARRAYFORMULA as well
try:
=ARRAYFORMULA(IF((H2:H >= -B39)*(H2:H <= B40), 100, IF( H2:H > B37, 0, )))

How to extract the upper triangular matrix w or w/o diagonal in Chapel

The best stories start with my matrix A.
var A: [{1..4,1..4}] real = (
(4, -30, 60, -35),
(-30, 300, -675, 420),
(60, -675, 1620, -1050),
(-35, 420, -1050, 700)
);
I recall somewhere you can get the upper triangle, but I can't find it in the Chapel docs Can you set it to in/exclude the diagonal?
Using the LinearAlgebra library:
use LinearAlgebra;
var A: [{1..4,1..4}] real = (
(4, -30, 60, -35),
(-30, 300, -675, 420),
(60, -675, 1620, -1050),
(-35, 420, -1050, 700)
);
var upperTriangle = triu(A);
// Confirm it worked
writeln(isTriu(upperTriangle));

'Pretty' visualization not applied in Combo Chart

I'm trying to format nicely this Combo Chart, so that the vertical axes on both sides share the same gridlines. However, the second Y-axis (right side) isn't formatted as viewWindowMode: 'pretty' automatically. The result is that the values start from 0 instead of 10,000.
By setting the min and max values:
viewWindowMode: 'explicit',
viewWindow: {
max: 14000,
min: 10000}
the outcome is nice, but the line touches top and bottom of the chart. So I tried giving it some padding by setting max: 15000and min: 9000, but then the number of gridlines increases and gridlines: {count: 6}doesn't seem to have an effect.
Is there a way to force viewWindowMode: 'pretty' on the second vertical axis?
The 'pretty' mode for an axis is going to result in unpredictable values, depending on where your data falls within the gridlines. So if you wish to coordinate the gridlines for both the left and right axes, you need to be more explicit about the viewWindow min and max for both, and the number of gridlines, or explicit ticks. You could do it like this: http://jsfiddle.net/dlaliberte/pyAz5/316/ Which uses these options:
var options = {
series: {
1: { targetAxisIndex: 1 }
},
vAxes: {
0: {
viewWindow: { min: 0, max: 1500 }
},
1: {
viewWindow: { min: 0, max: 1500 }
}
}
};
The gridlines.count option is not a guarantee in all cases because it could conflict with the heuristics for nice tick values.

Calculate enclosing rectangle of a given aspect ratio

Given the height and the width of a rectangle of any size and an aspect ratio, how can I calculate the height and width of a minimum enclosing rectangle of the given aspect ratio?
In code, the function signature would look like this
public Size getMinimumEnclosingRectangle(Size originalRectangle, float aspectNumerator, float aspectDenomiator);
Calls to this function would look like
originalRectangle AspectRatio Result
-------------------------------------------
100x100 1:2 100x200
64x32 1:1 64x64
125x100 3:2 150x100
100x345 1:3 115x345
This may not be the best way, but the way I do this calculation is to calculate the change in aspect ratio and then base the resulting width/height calculation of of that. Here is some code to illustrate this algorithm in practice:
var sourceImages = [
{width: 100, height: 100, toAspectRatio:1/2 },
{width: 64, height: 32, toAspectRatio:1/1 },
{width: 125, height: 100, toAspectRatio:3/2 },
{width: 100, height: 345, toAspectRatio:1/3 },
{width: 345, height: 100, toAspectRatio:1/3 }
];
function calculateNewSize( sourceWidth, sourceHeight, toAspectRatio )
{
var aspectRatioChange = (sourceWidth / sourceHeight) / toAspectRatio;
var fitWidth = aspectRatioChange < 1 ? sourceHeight * toAspectRatio : sourceWidth;
var fitHeight = aspectRatioChange >= 1 ? sourceWidth / toAspectRatio : sourceHeight;
console.log('(' + aspectRatioChange + ') ' + sourceWidth + " x " + sourceHeight + " -> "
+ toAspectRatio + ' -> ' + fitWidth + ' x ' + fitHeight);
}
sourceImages.forEach(function(source) {
calculateNewSize(source.width, source.height, source.toAspectRatio);
});

Animating an arc in Raphael JS wobbles in Chrome

I am seeing an annoying wobble in my animation, I have stripped out the code which contains the actual animation:
var side = 400;
var paper = new Raphael($(this), 100, side);
paper.customAttributes.arc = function (xloc, yloc, value, total, R) {
var alpha = 360 / total * value,
a = (90 - alpha) * Math.PI / 180,
x = xloc + R * Math.cos(a),
y = yloc - R * Math.sin(a),
path;
if (total == value) {
path = [
["M", xloc, yloc - R],
["A", R, R, 0, 1, 1, xloc - 0.01, yloc - R]
];
} else {
path = [
["M", xloc, yloc - R],
["A", R, R, 0, +(alpha > 180), 1, x, y]
];
}
return {
path: path
};
};
var arcWidth = 180 - 120;
var strokeRadius = (120 + arcWidth/2);
var indicatorArc = paper.path().attr({
"stroke": "#4B6384",
"stroke-width": 100,
arc: [side/2, side/2, 0, 100, strokeRadius]
});
indicatorArc.animate({
arc: [side/2, side/2, 75, 100, strokeRadius]
}, 1500, "<>", function(){
// anim complete here
});
I have put it in a jsfiddle for you to see for yourself, please check in firefox and chrome, you will notice in chrome the edges wobble substantially, is there anything I can do to eliminate this?
fiddle here: run many times
So I know this is over two years old now, but if anyone comes across this issue, it's a known bug within Chrome's 2D drawing engine.
https://code.google.com/p/skia/issues/detail?id=2769