Octave, barplot, only one row - bar-chart

I need to plot a bar graph in Octave. The following code:
clf;
data = rand(4, 5);
h1 = bar(data(1, :), "stacked");
l1 = legend("Col1", "Col2", "Col3", "Col4", "Col5");
legend(l1, "location", "northeastoutside");
figure
h4 = bar(data, "stacked");
l4 = legend("Col1", "Col2", "Col3", "Col4", "Col5");
legend(l4, "location", "northeastoutside");
does it. The second plot produces exactly what I need:
The first one, however, does not work as I would assume it would:
Is there any way to have a one-row bar plot that produces a graph with only one column in the style of the first plot?
Thanks in advance.
Rodrigo

This is not an elegant solution, but it can work in most of the cases.
The idea is to plot an additional bar (in x=2), and then hide it changing the
limits of the x axis (let's say [0.05, 1.95]):
M=zeros(2,4);
M(1,:)=rand(1,4);
bar(M, "stacked");
xlim([0.05 1.95]);
l1 = legend("Col1", "Col2", "Col3", "Col4", "Col5");
legend(l1, "location", "northeastoutside");

Related

X-scale does not update (sometimes) on signal change in a Vega chart

This is a somewhat simplified version of a chart I built recently. When I select the Extended time rage checkbox, more data points will show and the X axis will adjust accordingly.
When I clear the checkbox the additional data points will disappear (OK) but the X axis will not go back to the previous state (bug?).
Oddly enough if I change the time unit back and forth (for example monthly -> weekly -> monthly) then the X axis will eventually redraw correctly.
Why does this happen an how could I work-around the issue?
Also note that Y axis seem to update fine every time the checkbox toggles.
Chart renders with expected x-axis (when clicking checkbox) if xscale "domain" is changed from
"domain": {
"signal": "timeSequence(tbin_delivered.unit, tbin_delivered.start, tbin_delivered.stop)"
}
to
"domain": {"data": "deliveries", "field": "unit0", "sort": true}
Note: An issue with this workaround is that only time units with data are shown in the x-axis. For example, selecting time unit "daily" in the dropdown shows chart with no gaps for Saturday and Sunday when there were no deliveries.
Vega docs for ordinal scale and sort parameter:
https://vega.github.io/vega/docs/scales/#ordinal
https://vega.github.io/vega/docs/scales/#sort
View chart in Vega online editor
It looks like signal tbin_delivered is not updated when the time range shrinks. This is an edited chart; the only difference is in the tooltip (which will now show the value of tbin_delivered.start).
I wonder if this behavior is correct? tbin_delivered is calculated in the deliveries data stream, which is derived from stream fruit, which depends on the extendedtime signal, which does change.
Posting it as an answer because the link won't fit in a comment.
The issue appears to be the values of signal tbin_delivered.start and tbin_delivered.stop are not updated when dataset deliveries values are changed.
The workaround in this solution is to use Vega transform extent to obtain minimun and maximum values of the dataset after data have changed. The function timeSequence in xscale will then show the updated domain correctly.
Added Vega transform:
{
"type": "extent",
"field": "unit0",
"signal": "signal_delivered_extent"
}
Vega scale:
"scales": [
{
"name": "xscale",
"type": "band",
"range": "width",
"padding": 0.05,
"round": true,
"domain": {
"signal": "timeSequence(tbin_delivered.unit, signal_delivered_extent[0], signal_delivered_extent[1] + 1)"
}
Note that Vega expression function timeSequence: "Returns an array of Date instances from start (inclusive) to stop (exclusive)...". For the rendered x-axis domain to include the maximum value, the argument for stop in timeSequence function has to be higher than the maximum value in signal_delivered_extent.
View in Vega online editor

Change text box color in SSRS based on value

I am creating a SSRS report and I have column named Priority and I want to change background color of that particular box based on the value.
This is what I have tried
=SWITCH(Fields!Priority.Value = Critical, "Red", Fields!Priority.Value = High, "Green", Fields!Priority.Value = Average, "Yellow", Fields!Priority.Value = Low, "Blue")
Error:
The BackgroundColor expression for the text box ‘Priority1’ contains an error: [BC30451] Name 'Critical' is not declared.
Thank you
The values on the right side of your equal signs need to be in double quotes.
=SWITCH(Fields!Priority.Value = "Critical", "Red", Fields!Priority.Value = "High", "Green", Fields!Priority.Value = "Average", "Yellow", Fields!Priority.Value = "Low", "Blue")
EDIT: Just to add a little description in case it's not clear: you need those double quotes since you're comparing to those strings. Bare words in expressions are assumed to be keywords, so when it gets to the word Critical and can't find any keyword associated with that, it doesn't know what to do. If you were comparing numbers, you would not need the quotes, but since you are dealing with strings in this case, you do.

Higstock add all series dynamically

I've a Higstock lineal graph. Sometimes I need to show just one serie, other times I need two or three series to draw.
Obviously, this is an example of adding series dynamically. I put:
$(function() {
var chart = new Highcharts.StockChart({
// ...
series: []
// ...
})
chart.addSeries({name : "Value1",data : value1Data});
chart.addSeries({name : "Value2",data : value2Data});
chart.addSeries({name : "Value3",data : value3Data});
But not working, the chart needs to have at least one serie with data values in "series" node, not allowing an empty series node, like I put before.
I need to add all my series dynamically.
Anyone can help me? Thanks.
Example: http://jsfiddle.net/8aP69/1/
FYI: The graph only draws the navigation bar.
After many little test, a man that I loved him give me the solution.
I need to set initial series node like that:
series: [{ name: "Serie1", data : [null]}] // first serie has to be null
And after that, adding data point for first serie.
chart.series[0].setData(data1); // adding his data here

changing bar fill colours in ssrs chart

SO Post
Current I've got 5 bars in my RS chart - in the future there might be 7 bars or 17 bars or 27 bars!
With a couple of bars I can have an expression like this:
=iif(Fields!Market.Value = "Spain"
,"Gold"
,iif (Fields!Market.Value = "Denmark"
, "Gray"
, iif(Fields!Market.Value = "Italy"
, "Blue"
, "Purple"
)
)
)
If I can't predict how many countries will be included + I'd rather not have to hard code in "Green", "Red" etc how do I change the expression?
I've tried this but it is erroring:
=Switch(Mod(Fields!Rank.Value/CDbl(2))=CDbl(0), "Gold",
Mod(Fields!Rank.Value/CDbl(3))=CDbl(0), "Gray",
Mod(Fields!Rank.Value/CDbl(2))>CDbl(0) "Blue")
Above is the totally incorrect syntax: This works:
=Switch(CDbl(Fields!Rank.Value Mod 2)=CDbl(0), "Gold",
CDbl(Fields!Rank.Value Mod 3)=CDbl(0), "Gray",
CDbl(Fields!Rank.Value Mod 2)>CDbl(0), "Blue")
Ok - the above runs (not sure how!) but the below is based on help from Dominic Goulet and is really easy to follow and nice and expandable to more colours; this is the solution for 5 colours:
=Switch(CDbl(Fields!Rank.Value Mod 5)=CDbl(0), "Gold",
CDbl(Fields!Rank.Value Mod 5)=CDbl(1), "Gray",
CDbl(Fields!Rank.Value Mod 5)=CDbl(2), "Green",
CDbl(Fields!Rank.Value Mod 5)=CDbl(3), "Red",
CDbl(Fields!Rank.Value Mod 5)=CDbl(4), "Pink")
First of all, instead of using many "IIF"s, you should use "Switch", it's leaner that way.
Switch(Fields!Market.Value = "Spain", "Gold",
Fields!Market.Value = "Denmark", "Gray",
Fields!Market.Value = "Italy", "Blue")
Now if you want a color per coutry, you should defenitely store that in your database and pull it out when you need it. That way, a country will always have the same color on every report you have.
It would be better to create a function. For that, go to Report Properties, choose code and type this example :
Public Function Color(ByVal Index as Integer) as String
Select Case Index
Case = 1
return "#a6cee3"
Case = 2
return "#1f78b4"
Case = 3
return "#b2df8a"
Case = 4
return "#33a02c"
Case = 5
return "#fb9a99"
Case = 6
return "#e31a1c"
Case = 7
return "#fdbf6f"
Case = 8
return "#ff7f00"
Case = 9
return "#cab2d6"
Case = 10
return "#6a3d9a"
End Select
End Function
On the Fill option from "Series Properties->Pick color-> Color choose fx
put this code
=Code.Color(rownumber(nothing))
Each bar will have a color.
For the HEX colors I took from the website : http://colorbrewer2.org/#type=qualitative&scheme=Paired&n=10
It shows the best colors that match with each other, so you don't need to think of that. And you can add as many colors as you want

SSRS customized pie chart color

I have a doubt here,
I need to show a pie-chart in SSRS, for the student results according to their status(Pass/Fail).......I have only 4 conditions Male-pass,Male-fail,Female-pass,Female-fail,I need to show these things with my own color,
for this am using the switch condition as
=Switch(
((Fields!Gender.Value = "Male")&(Fields!Status.Value="Pass")), "Blue",
((Fields!Gender.Value = "Male")&(Fields!Status.Value="Fail")), "HotPink",
((Fields!Gender.Value = "Female")&(Fields!Status.Value="Fail")), "Orange",
((Fields!Gender.Value = "Female")&(Fields!Status.Value="Pass")),"LimeGreen" )
but in the preview it shows only the default color set, not the customized one, can anyone fix this one...thanks in advance
Try using something like
=IIf((Fields!Gender.Value = "Male") and (Fields!Status.Value="Pass"),"Green",
IIf((Fields!Gender.Value = "Male") and(Fields!Status.Value="Fail"),"Red" ,
IIf((Fields!Gender.Value = "Female") and (Fields!Status.Value="Fail") ,"Blue",
(Fields!Gender.Value = "Female") and (Fields!Status.Value="Pass"),"Yellow","Orange"
,"#00000000"))))
You should be able to get it working using the Switch statement as well. The problem with your expression is that the logical "and" operator in SSRS is And, not ampersand. In SSRS, a single ampersand is used for concatenating strings. So your expression is concatenating the string representation of the two boolean results, resulting in strings like TrueFalse. This should actually giving an error on the Switch evaluation.
A correct Switch statement would be this:
=Switch(
Fields!Gender.Value = "Male" And Fields!Status.Value="Pass", "Blue",
Fields!Gender.Value = "Male" And Fields!Status.Value="Fail", "HotPink",
Fields!Gender.Value = "Female" And Fields!Status.Value="Fail", "Orange",
Fields!Gender.Value = "Female" And Fields!Status.Value="Pass","LimeGreen"
, True, "SomeOtherColor"
)
I've also added an "else" part to the switch in case some records are not covered by the other conditions. If you're 100% sure that won't happen, you can remove the line that starts with "True". But it shouldn't hurt to keep it either.
More info: Pie Chart Techniques (look for Custom Coloring chapter)