Set width of y-axis labels in CanvasJS? - canvasjs

I'm looking for a way to set the width of the labels along the Y axis using CanvasJS. I can set the max-width, but that's not what I want. I'd like to be able to simply set the width to eg. 200px, and just have extra space to the left or right of the label if it happens to be shorter.
A little background: we're showing 3 separate column charts vertically on a page & need the Y axes to line up. The width of the labels for each of the 3 charts varies though.
Current results (bad, Y axes not lined up)
1,500 |
1,000 | [chart 1]
500 |
0 -----------------
0.4 |
0.3 | [chart 2]
0.2 |
0.1 |
0 -----------------
$40,000 |
$30,000 | [chart 3]
$20,000 |
$10,000 |
$0 -----------------
Desired results (good, Y axes lined up)
1,500 |
1,000 | [chart 1]
500 |
0 -----------------
0.4 |
0.3 | [chart 2]
0.2 |
0.1 |
0 -----------------
$40,000 |
$30,000 | [chart 3]
$20,000 |
$10,000 |
$0 -----------------
Thanks!

I'm not sure if you can achieve that. But you can use margin and align all the charts. However, the labels won't start from the left position. Instead, it'd create a gap before the label starts.
axisY: [{
labelMaxWidth: 100,
prefix: "This"
}]
You'd have to set the value of margin to align it. To do so, you can use set method.
chart2.axisY[0].set("margin", chart.axisY[0].bounds.x2 - (chart2.axisY[0].bounds.x2 - chart2.axisY[0].bounds.x1));
Here is a working fiddle. Hope that helps.

Related

Grafana & Elastic - How to count sub array length

So I have a document that has two nested arrays i.e.
foo.bars[].baz[]
I am trying to figure out how I can use graphana to group by bars and give me a count of bar's for each bar. So it would look something like:
| bars.id| count|
| 1 | 10 |
| 2 | 15 |
| 3 | 20 |
What I have tried is the following:
Group by bars.id
Add a Sum metric for bars.baz.id
Override the script value to return 1
While this does give me the count of the bars, it does so for all bars in the document and not grouped by the bars.id i.e.
| bars.id| count|
| 1 | 45 |
| 2 | 45 |
| 3 | 45 |
Any help to achieve this would be very helpful.
Now if this can be done I have another more complex problem. I have another collection let's call it bobs that is a child of the root document. Now bobs isn't nested under the bars array but it has a bar.id field. I would also like to sum this based on that i.e.
{
bobs: [
{bar_id: 1},
{bar_id: 2},
],
bars: [
{id: 1, bazes: []},
{id: 2, bazes: []}
]
}
In this case I would also like in the table:
| bars.id| bobs.count|
| 1 | 1 |
| 2 | 1 |
| 3 | 0 |
Is this possible?

turned on bits counter

Suppose I have a black box with 3 inputs (each input is 1 bit) and 2 bits output.
The black box counts the amount of turned on input bits.
Using only such black boxes,one needs to implement the counter of turned on bits in the input,which has 7 bits.The implementation should use the minimum possible amount of black boxes.
//This is a job interview question
You're making a binary adder. Try this...
Two black boxes for input with one input remaining:
7 6 5 4 3 2 1
| | | | | | |
------- ------- |
| | | | |
| H L | | H L | |
------- ------- |
| | | | |
Take the two low outputs and the remaining input (1) and feed them to another black box:
L L 1
| | |
-------
| |
| C L |
-------
| |
The low output from this black box will be the low bit of the result. The high output is the carry bit. Feed this carry bit along with the high bits from the first two black boxes into the fourth black box:
H H C L
| | | |
------- |
| | |
| H M | |
------- |
| | |
The result should be the number of "on" bits in the input expressed in binary by the High, Middle and Low bits.
Suppose that each BB outputs a 2-bit binary count 00, 01, 10, or 11, when 0, 1, 2, or 3 of its inputs are on. Also suppose that the desired ultimate output O₄O₂O₁ is a 3-bit binary count 000 ... 111, when 0, 1, ... 7 of the 7 input bits i₁...i₇ are on. For problems like this in general, you can write a boolean expression for what the BB does and a boolean expression for the desired output and then synthesize the output. In this particular case, however, try the obvious approach of putting i₁, i₂, i₃ into a first box B₁, and i₄, i₅, i₆ into a second box B₂, and i₇ into one input of a third box B₃. Looking at this it's clear that if you run the units outputs from B₁ and B₂ into the other two inputs of B₃ then the units output from B₃ is equal to the desired value O₁. You can get the sum of the twos outputs from B₁, B₂, B₃ via a box B₄, and this sum is equal to the desired values O₄O₂.

Oracle reports center aligning the header of a field in a repeating frame

I have a label and a field as in the follwing layout.
________________
| _____ |
| | | |
| |Label| |
| |_____| |
| |
| ____________ |->Outer fixedframe
| | _______ | |
| | | | | |
| | |field| | |
| | |_____| | |
| |__>_______| |
| | |
| -->Inner |
| Horizontally expanding repeating frame
|______________|
I would like to center align the label with respect to the field in the inner repeating frame. For example,
If the repeating frame generates 5 fields, the label needs to be right above the 3rd field.
Is this possible using oracle reports or any alternate layouts?. Any help would be much appreciated
I just got this working with a quick mock-up and here is how I did it:
1) Select the "Anchor" tool from the tool palette and anchor the bottom middle "outline square" (I'm not sure what the technical term for those are but the grab-points on an object where you can resize them) from the label object and connect it to the top middle "outline square" of the horizontal repeating frame.
2) [Optional] Click on the anchor line and check the properties to make sure the Child Edge Type is set to "Bottom", the Child Edge Percent is "50", the Parent Edge Type is "Top", and the Parent Edge Percent is "50".
3) Click on the label and set the Keep With Anchoring Object property to "Yes".
4) Make sure your label is centered over the repeating frame in the Paper Layout view. I noticed that if it is off-centered to start with it will be off-centered by the same amount when run. I ended up making the label the same width as the repeating frame it was over and then set both to a Horizontal Elasticity of "Variable".
I ran this with 5 horizontally repeated objects and then I added a 6th to verify it remained centered and both worked.
Hope that helps and that I didn't miss a step. I'll save the mock-up in case it needs further steps or explanation.

A rule for Checkers(draughts) Deadlock

I am writing a program that play Checkers against human, with a min-max game tree. Everything went fine until facing a problem. Here is the scenario described as an illustration.
->Let X be a black cell, 0 be an empty cell, B be a black stone and W be a white stone;
->The board is showed as follows;
| X | B | X | B | X | B | X | B | X |
| W | X | B | X | B | X | B | X | B |
| X | 0 | X | 0 | X | 0 | X | 0 | X |
| 0 | X | 0 | X | 0 | X | 0 | X | 0 |
( and there is no stone underneath)
-> It is White players turn and white player does not any moves to play. He/she only have one stone and it got stuck.
What is the outcome of this game, i.e. who wins and who loses. Should I declare a draw?
How can I solve this deadlock? Is there any official reference that states a rule for this kind of deadlock?
Thank you very much.
According to this site:
http://boardgames.about.com/cs/checkersdraughts/ht/play_checkers.htm
13 A player wins the game when the opponent cannot make a move. In most cases, this is because all of the opponent's pieces have been captured, but it could also be because all of his pieces are blocked in.
So I guess in such a situation, the black would be a winner since all of the white's pieces are blocked.
I have never messed with min-max trees, how ever, you might check to see if the at least one of the pieces that a side has, either black or white, has one possible move, ie. a child.
If no nodes have children, then, it would mean that no moves can be done, thus, the opposing side has won the game.

Jasper report: two detail sections?

I've got a jasper report to do, with data like this:
Item | Quantity | Color
------+-----------+--------
A001 | 1 | Red
A001 | 1 | Green
B002 | 3 | Red
B002 | 3 | Purple
The report is grouped by Item/Quantity, e.g.
Item: A001, Qty: 1, Colors: Red,Green
Item: B002, Qty: 3, Colors: Red,Purple
Now I've got this Jasper report that already groups as such - i.e. shows a heading with the item and quantity, with a list of colors underneath.
The question now is, underneath this group I need to display a number of horizontal lines (for someone to write something in), equal to the qty of the item. e.g. underneath the A001 group I need to display one line, and under the B002 group I need to display three lines, like so:
Item A001, Qty 1, Colors Red, Green
_________________________
Item B002, Qty 3, Colors Red, Purple
_________________________
_________________________
_________________________
I've tried looking at jasper scripts, but it seems they can only manipulate report parameters/variables.
Does anyone have an idea of how I could do this?
Hmm, interesting.
Here is what you could do:
Using this source data (MySQL):
create table items (
item varchar(4),
quantity number,
color varchar(10),
);
(insert data...)
create table numbers (i integer)
(insert data 0, 1, 2 .... MySQL 5.1 has stored procedures that could do it, earlier versions would need an external script to populate it. Go from 0 to the largest quantity you'd have).
Then, the trick is to craft the right sort of query. I came up with this:
select i.*, n.i from
(
select concat(i.item, ' ', i.quantity) as grouping, i.item, i.quantity,group_concat(distinct color) as colors
from items i
GROUP BY item, quantity
) i
cross join numbers n
where quantity > n.i;
E.g. If I populate my numbers table, and the populate the items table with your example data, and then run the query I get:
+----------+------+----------+------------+------+
| grouping | item | quantity | colors | i |
+----------+------+----------+------------+------+
| A001 1 | A001 | 1 | Red,Greem | 0 |
| B002 3 | B002 | 3 | Red,Purple | 0 |
| A001 1 | A001 | 1 | Red,Greem | 1 |
| B002 3 | B002 | 3 | Red,Purple | 1 |
| A001 1 | A001 | 1 | Red,Greem | 2 |
| B002 3 | B002 | 3 | Red,Purple | 2 |
| A001 1 | A001 | 1 | Red,Greem | 3 |
| B002 3 | B002 | 3 | Red,Purple | 3 |
+----------+------+----------+------------+------+
Then in your Jasper Report, the trick is to create a group/band that works off the 'grouping' column, and put your heading in that:
Item A001, Qty 1, Colors Red, Green
And then, in the detail section just have a line as the only thing in the detail.
Doing this generates the report you want for me.
Note that the numbers table is a little silly, but is a standard data warehousing technique, though I suspect some database (e.g. Oracle) would have clever recursive procedures or other functions that would exclude the need for it.
OK, in the end, this was done using a subdataset and a crosstab in the detail footer section. Works nicely - thanks for everyone who contributed :)

Resources