I've exhausted my understanding of Tableau. I'm trying to color every icon below the risk average the color red, and above the color green. Here is an attempt at an articulation in Java of my intention (this code may not be correct, but I want the intention translated into Tableau).
This is my Tableau code that doesn't work:
IF [Commercial Services] <= [Risk Average] *The variable I want to create*
THEN "Red"
ELSEIF [Commercial Services] > [Risk Average]
THEN "Green"
END
Here's the Java code I think is closer to what I need converted:
final int NUM_ROWS = 39;
int count = 0;
while(count < NUM_ROWS) {
if(count.commercial_services < count.risk_average) {
shape.color = "Red";
} elseif(count.commercial_services > count.risk_average) {
shape.color = "Green";
} else {
shape.color = "Blue";
}
count++;
}
Please help me create a variable that I could use to color each risk in reference to the risk average.
I have attached a spreadsheet and an image for reference.
Thanks in advance.
That is not the way Tableau works. For such purposes, you should first create a flag-like calculated field to form values according to your conditions. And then use that field as a shape or color identifier dragging it to the Marks card.
So for your case you may create a field like below (which is almost the same you did), which means it will have the value of "Red" for CS<=RA condition and "Green" for the other condition. Only that Tableau does not know what to do with these string variables at the moment. You may assign -1 or 1 instead of these strings, it does make no change.
IF [Commercial Services] <= [Risk Average]
THEN "Red"
ELSE "Green"
END
And now you have new column in your data which have "Red" or "Green" values at each row. You may now drag this field to Marks card and select is as Color or as normal pill and select its type as Shape then use standard arrows or make your custom shapes according to your needs. At this phase, you will be selecting with which colours or shapes should your "Red" & "Green" values be represented by.
I or someone else might be in more help if you share your tableau workbook with what you have done so far.
Related
1) I'm practicing stuff with graphs in order to add that feture to my app, I want the upper labels ( the xAxis base ) to be shown only where entries occur.
I haven't found a suitable solution online yet, and currently it appears on every xAxis from first entry to last entry as in the picture below:
I want it to be without the one sI deleted, as shown in the picture below:
2) and the second question I'm struggling with it is that I want to be able to draw for example in (x=5, y=7) and after it to draw at (x=1, y =3), but it wont let me add an entry with a smaller x that any other entry that already in the graph.
You have to extend from ValueFormatter class.
for more detail take a look at link
You can pick your desired logic to make the label disappear with returning "".
for example:
public String getFormattedValue(float value) {
if ((int)value <= 0) //your logic to evaluate correctness
return ""; // make lable go away
//...
}
UPDATE 2 (in Kotlin):
There is another overload for getFormattedValue which have a AxisBase parameter and you can use mEntryCount or mEntries.
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
if (axis?.mEntryCount!! <= 0)
return ""
}
the problem consists in that you have to solve a problem where exists n-cities and n-colors , every city have a color but the cities adjacent can't have the same color.
The teacher send this homework for investigate how to solve it , we are working on java - eclipse and we are so confused . Can you help us being really explicit , thanks so much. the last topic was recursion.
P.D: some people say that it solve by graphs but we are not sure and we dont understand really good .
If I were you, I would make 2 loops for, one inside the other, like this:
for (i = 0; i < n_cities; i++)
{
for (j = 0; j < n_colours; j++)
{
}
}
In this way, you will be able to walk all the possible combinations. In the second loop, you will have to make the comparison if the cities around citie i have the same colour, if not, try with the next colour, and this for all the n-iterations.
How to know if the cities adjacent are with the same colour? Well, you can create a n-vector in which you will save all the colours of all the cities. The position of the vector could be the i-citie and the value saved in the position could be the colour of this citie.
I expect it will be useful for you :)
There are probably many solutions, but the first one that came to mind is having an ArrayList containing CityColor instances. My CityColor class holds the city name and color. When adding to the ArrayList, you would check to make sure the adjacent elements of the ArrayList do not have the same color. If it does have the same color, use recursion to select another color until you get an acceptable color.
Your ArrayList would have objects such as:
public class CityColor {
private String city;
private String color;
public CityColor(String city, String color) {
this.city = city;
this.color = color;
}
// set/get methods for the variables
}
If you have an array of colors, you can use Math.Random to select a random color. If the color matches an adjacent color, use recursion to select another.
I'm currently working on a program of mine for personal development as a programmer and I have hit a miniature brick wall of frustration on this mouseclicked event I'm working on. When I thought up the procedure in my mind and on the white board I saw it utilizing a switch statement to get the job done. I have met with no success with this plan. I have since experimented with a few other control structures, but nothing seems to work the problem is controlling the control structure inside the mouseClicked event. I'll provide some relevant example code to try to communicate my objective. Note that I know the provided code is bad. I'm just trying to communicate an idea.
The goal is to be able to have the box start out green, then the user can click the box turn it red, click again it goes white, and one last time it goes back to green. For some reason this is beyond me at the moment. Any and all help will be greatly appreciated. Thanks in advance!
//This component allows the user to store information on current unit identifier. Maybe necessary to pass this in as an arguement to the PssGui since there is no accounting for callsigns.
//This component also needs to be updated with a mouse click event that can turn the color of the box to reflect the tooltip text.
unitId = new JTextField();
unitId.setEditable(false);
unitId.setBackground(Color.GREEN);
unitId.setHorizontalAlignment(SwingConstants.CENTER);
unitId.setToolTipText("<html>SHADE CELLS TO REFLECT CURRENT UNIT STATUS:" + "<br/>GREEN-MC" + "<br/>RED-NMC" + "<br/>WHITE-UNIT IN TRANSISTION</html>");
unitId.setText("A 4/5");
unitId.setBounds(0, 116, 79, 172);
getContentPane().add(unitId);
unitId.setColumns(10);
unitId.addMouseListener(new MouseAdapter() {
#Override
public void mouseClicked(MouseEvent arg0) {
//Fill with sweet code to change the color of this box accordingly.
//use an Int and a while loop or something so that every click increments the Int
//then each int value corresponds to a color
// have a statement at the end that resets the int back to zero to keep the colors in the loop
//I.E int color = 0, mouse click happens int color = 1, now color =1 which turns the box red,
//color can never be greater than 3, when it is, we set color back to zero.
for(int i = 0; i<=3; i++){
switch (i){
case 1: unitId.setBackground(Color.GREEN);
break;
case 2: unitId.setBackground(Color.red);
break;
case 3: unitId.setBackground(Color.white);
break;
}
}//end while
//System.out.println(i);
}
});
Addendum:
I fixed my own problem. I knew it was going to be something trivial and I apologize if posting here was a waste of server resources. I was massively frustrated last night when I was trying to solve this problem. Here is the functional code. The lesson to remember here is to take a break and don't always try to force the solution.
unitId = new JTextField();
unitId.setEditable(false);
unitId.setBackground(Color.GREEN);
unitId.setHorizontalAlignment(SwingConstants.CENTER);
unitId.setToolTipText("<html>SHADE CELLS TO REFLECT CURRENT UNIT STATUS:" + "<br/>GREEN-MC" + "<br/>RED-NMC" + "<br/>WHITE-UNIT IN TRANSISTION</html>");
unitId.setText("A 4/5");
unitId.setBounds(0, 116, 79, 172);
getContentPane().add(unitId);
unitId.setColumns(10);
unitId.addMouseListener(new MouseAdapter() {
#Override
public void mouseClicked(MouseEvent arg0) {
//Fill with sweet code to change the color of this box accordingly.
//use an Int and a while loop or something so that every click increments the Int
//then each int value corresponds to a color
// have a statement at the end that resets the int back to zero to keep the colors in the loop
//I.E int color = 0, mouse click happens int color = 1, now color =1 which turns the box red,
//color can never be greater than 3, when it is, we set color back to zero.
if(starter==0){
unitId.setBackground(Color.GREEN);
starter++;
}
else if(starter==1){
unitId.setBackground(Color.WHITE);
starter++;
}
else if(starter==2){
unitId.setBackground(Color.RED);
starter++;
}
else{
starter=0;
unitId.setBackground(Color.GREEN);
}
//System.out.println(i);
}
});
I got a relatively easy question - but I cannot find anything anywhere to answer it.
I use a simple SWT table widget in my application that displays only text in the cells. I got an incremental search feature and want to highlight text snippets in all cells if they match.
So when typing "a", all "a"s should be highlighted.
To get this, I add an SWT.EraseItem listener to interfere with the background drawing. If the current cell's text contains the search string, I find the positions and calculate relative x-coordinates within the text using event.gc.stringExtent - easy.
With that I just draw rectangles "behind" the occurrences.
Now, there's a flaw in this. The table does not draw the text without a margin, so my x coordinate does not really match - it is slightly off by a few pixels! But how many?? Where do I retrieve the cell's text margins that table's own drawing will use? No clue. Cannot find anything.
Bonus question: the table's draw method also shortens text and adds "..." if it does not fit into the cell. Hmm. My occurrence finder takes the TableItem's text and thus also tries to mark occurrences that are actually not visible because they are consumed by the "...".
How do I get the shortened text and not the "real" text within the EraseItem draw handler?
#Override
public void handleEvent( final Event event ) {
final TableItem ti = (TableItem) event.item;
final int index = event.index;
final GC gc = event.gc;
if( ti == null || currentSwyt.isEmpty() ) {
return;
}
final String text = ti.getText( index );
if( !text.contains( currentSwyt ) ) {
return;
}
// search text is contained
final String[] parts = text.split( currentSwyt );
final int swytWidth = gc.stringExtent( currentSwyt ).x;
// calculate positions, must be relative to the text's start
int x = event.x; // THIS IS THE PROBLEM: event.x is not enough!
final int[] pos = new int[parts.length - 1];
for( int i = 0; i < parts.length - 1; i++ ) {
x += gc.stringExtent( parts[i] ).x;
pos[i] = x;
}
final Color red = event.display.getSystemColor( SWT.COLOR_RED );
final Color oldBackground = gc.getBackground();
gc.setBackground( red );
for( int j = 0; j < pos.length; j++ ) {
gc.fillRectangle( pos[j], event.y, swytWidth, event.height );
}
gc.setBackground( oldBackground );
event.detail &= ~SWT.BACKGROUND;
}
I think it would be quite useful for you to have a look at TableViewer and StyledCellLabelProvider. That will make your task a lot easier I think considering the kind of text formatting you require. Since the drawing is than completely handled by the label provider, you can avoid these pesky margin issues.
As for almost all SWT Widgets, this might be OS dependent. The actual "drawing" of the table is done using OS resources.
However, it might be worth having a look at TableItem#getTextBounds(int).
It returns a Rectangle that should reflect the margins.
For your bonus question: I have never seen the text being shortened automatically in my applications. In fact I had a hard time doing this myself. But that might as well be OS dependent, since I use Linux.
I've seen this in a code of tetris game and I'm wondering how these values are able to draw the line, T-shape, S-shape, Z-shape, L-shape, inverted-L and a sqaure.
I get the four parametes maybe because of the four blocks needed per piece. But how did they come up with values like that? Have those something to do with the color too?
int blocks[][] = {
{0x0f00, 0x4444, 0x0f00, 0x4444}, // LINE
{0x04e0, 0x0464, 0x00e4, 0x04c4}, // T
{0x4620, 0x6c00, 0x4620, 0x6c00}, // S
{0x2640, 0xc600, 0x2640, 0xc600}, // Z
{0x6220, 0x1700, 0x2230, 0x0740}, // 7
{0x6440, 0x0e20, 0x44c0, 0x8e00}, // inverted 7
{0x0660, 0x0660, 0x0660, 0x0660}, // square
}
I'm new in Java and I want to learn to "draw" using those values. Thank you very much!
Each row of the table is one shape. Each column is a different rotation for the shape. The square, for instance, is the same no matter how you rotate it. The line (first row) flips between two patterns. I found this in a web search:
http://codeincomplete.com/posts/2011/10/10/javascript_tetris/