Octave: How to create a legend for grouped bar graphs? - octave

I'm using Octaves "bar" command to plot a grouped bar graph based on data loded from a matrix stored in an external file. A similar plot based on random data can be created using this command:
bar(rand(4, 6));
I'd like to create a legend explaning the 6 bar colors occurring in each group instead of a legend for the 4 bar groups themselves. Executing the command
legend({"Probe 1", "Probe 2", "Probe 3", "Probe 4", "Probe 5", "Probe 6"});
creates the legend labels but does not assign the bar colors. Is there a way to fix this?

According to the Octave legend documentation, specifically examples 18 and 19, you should get what you are looking for with either legend('Probe 1', 'Probe 2', ...); or with legend({'Probe 1', 'Probe 2', ...});. Maybe try changing your quotations to single-quotes.
You can also get a handle to your bar graph with:
b = bar(rand(4, 6));
And then plot the legend with color boxes with:
legend(b, 'probe 1', 'probe 2', ...);
Edit: I tested each of the above methods and they all produced the legend that I believe you are looking for. The result looked slightly different than the figure here (made with MATLAB), but functionally the same. Oddly enough, so did your syntax (with double quotes instead of single). Are you plotting the figure in X11? Or are you plotting anything on top of the bar chart before generating the legend? Passing the handle to the bar chart should solve the latter case.

Related

Customize the vAxis values in a Google Sheets Line Graph

I'm making a Sheet to be used by elementary students, to track some energy "usage" in their class, based on a date. To make it dead easy, I've created dropdowns for their choices (text).
In order to make a graph, I've changed the choices into numbers ("All"=3, "Some"=2, "None"=1, "N/A"=0) onto another tab (using Apps Script). This makes a nice graph, but the vertical axis of course shows the numbers. I'm hoping there is a way to swap them out for the text.
I've tried the 'ticks' option, but nothing changes:
var vAxisOptions = {
0: {
ticks: [{v:0, f:'N/A'}, {v:1, f:'None'}, {v:2, f:'Some'}, {v:3, f:'All'}, {v:4, f:''}],
maxValue: 4,
gridlines: {count: 5} //add an extra line of space to see the lines better
}
};
And then apply it by .setOption('vAxes', vAxisOptions).
I suspect this just isn't possible, but is it? Thanks!!
Example: https://docs.google.com/spreadsheets/d/1zOeXJy92LdCmhdLW6MmLA0JCNVk34kk50B3tQGACwlY/edit?usp=sharing
p.s. Click the "View Results" button to make the graph if you make data changes
There is this Google Issue tracker issue on this matter that it is being worked on.
You can go there and click on the star next to the title of the issue so you will get updates on the issue.

SSRS chart lines not connecting

I have an SSRS Line chart which plots supply points with square feet on the X axis and Price on the Y axis. Right now I don't really care about making it pretty just getting the lines to show up correctly. I am plotting the points and grouping by Subdivision/Builder.
So for example Subdivision A has builders Y and Z. I want to show different colors and lines for Subdivision A builder Y verses Subdivision A Builder Z.
The problem is that the lines are not connecting when a point for another subdivision builder combination breaks up that line.
The grey line and points below are not all connected as the yellow point is between the grey points so the grey line is not connected to all grey points.
How can I make the points of the same color (same Subdivision/Builder) connected via a line?
As I found out the hard way recently, this problem is often caused by null values in the data not being properly handled by SSRS. Without seeing your data, I can't be certain that's the cause, but nulls were the culprit I encountered the same behavior.
The solutions usually involve assigning values to the color of the EmptyPoint property on the Series, sometimes in conjunction with setting the EmptyPointValue to specify null handling. I've found many references to this problem on the web, but I'll only post links to the best two, both of which are on StackExchange:
The thread SSRS Line Chart NULL VALUE - Horizontal Line contains a thorough discussion of this issue. The usual workaround given is to hard-code a color expression for each line using an IIf, but sometimes this isn't an option, especially if the field you're grouping on has dynamic, unpredictable values, as my dataset did.
The picture posted there depicts clear examples of the same type of line breaks. The user named trubs posted a code sample which illustrates how to set the EmptyPoint, in case where an Iif will work:
=iif(isNothing(Fields!SelectedValue.Value),'No Color',"LightBlue")
The first reply in SSRS Line Chart Not Connecting Data Points details a workaround for cases when the EmptyPoint value & nulls are the root cause and simple hard-coded IIfs won't do the trick. Although I have yet to get my line colors to match the point markers the way I'd like, I can verify that this solution at least gives you your lines back and allows you to assign a variety of colors to them. It's fairly simple and involves merely pasting in some VB code for a couple color properties.
I was asked in the comments section to provide the details of the solutions, but don't want to plagiarize, so I'll simply do a long direct quote of JohnBob's answer:
Firstly, in order to get the lines to join up, you need to set the
EmptyPoint colour for the series.
Select your series in your chart In the properties tab (not the
dialog) drill down into the EmptyPoint property and set the colour to
be Black
This will get them joining up - yay! But part of the line is colour
and the other part is black, right? That's a bit silly, especially
considering if you leave the colour to Automatic on the EmptyPoint
that it will be transparent.
So, then we need to get the series and the EmptyPoint's colours in
sync. Using code from here. I added some code to the code of the
report.
1). Right click on an empty space on the report and select "Report
Properties" 2). In the code tab, paste the following:
Private colorPalette As String() = {"#418CF0", "#FCB441", "#E0400A", "#05642E", "#1A3B69", "#BFBFBF", "#E0400A", "#FCB441", "DarkBlue", "Tomato", "Orange", "CornflowerBlue", "Gold", "Red", "Green", "LightBlue", "Lime", "Maroon", "LightSteelBlue", "Tan", "Silver"}
Private count As Integer = 0
Private mapping As New System.Collections.Hashtable()
Public Function GetColor(ByVal groupingValue As String) As String
If mapping.ContainsKey(groupingValue) Then
Return mapping(groupingValue)
End If
Dim c As String = colorPalette(count Mod colorPalette.Length)
count = count + 1
mapping.Add(groupingValue, c)
Return c
End Function
Then we need to call this code when setting the colour of the series
and of the EmptyPoint.
Select your series
In the properties tab paste something the following (replace WhateverTheGroupIsForYourSeries with your series group name):
=Code.GetColor(Fields!*WhateverTheGroupIsForYourSeries*.Value)
Drill down to the color element of the EmptyPoint Series property
Paste the same text as from point two [e.g. =Code.GetColor(Fields!*WhateverTheGroupIsForYourSeries*.Value)]
And voila! You're done! I can't believe how unnecessarily difficult
this is :D
I hope this helps.
Just put your Fields!(YourSeriesGroup).Value in Series Groups to above of
Fields!(YourCategoryGroup).Value in Category Groups, your series group should be in both Series Groups and Category Groups (should be above of your initial category group).
And after that right click horizontal axis and select Horizontal Axis Properties. Set Axis Type to Scalar and click OK.

SSRS - Line chart label influenced by seperate custom code?

I have encountered a really weird bug?? in SSRS as I try to implement a line chart with only the last data label. The chart displays predictive linear regression measures and I have implemented a custom code function in the code-behind that determines the color of the "predictive" line (based upon a lookupset which determines if the trend is up or down). I want to have conditional logic that so that only the last point on the line is shown in the label which is usually not a big problem but this time I'm running into issues. As soon as I call the custom code function to determine line color, the last point on my line shows the second last point's field value. If staticly set the line to have a color of "Red", then the last point has it's own field value as the data label.
This would be much easier to explain if I could post my screenshots, but I'll try to layout a scenario if clarification is needed:
Scenario 1) Line color determined in code-behind
Formulas in report:
Line data label: Trim(Fields!Month.Value)
Category label: Trim(Fields!Month.Value)
Line color: Code.TrendDirection(LookupSet(1, Fields!Lookup.Value, Fields!MonthTrend.Value, "FacilityTrends"))
Values for last data point:
Line data label: Mar-2014
Category label: Apr-2014
Line color: Red (as properly determined by code behind)
Scenario 2) Line color set statically
Formulas in report:
Line data label: Trim(Fields!Month.Value)
Category label: Trim(Fields!Month.Value)
Line color: "Red"
Values for last data point:
Line data label: Apr-2014
Category label: Apr-2014
Line color: Red
Why would the custom code expression for line color affect the field value of the last line data point? Any ideas?

SSRS group on only one value on a chart

I have data that I need to present in both a bar and line chart as one this how the chart is laid out in SSRS:
Series Group: Location
Category Group: Year
Category Group: Month
Values (Y Axis): Site_count (Bar chart)
Values (Y Axis):Network_count (Line chart)
My issue is that the Correspondences_count for both of these are being grouped by location. I need to prevent the line chart one being added to the location grouping, so that way it shows a single line.
I found this, that seems to show how this might be able to be done.. . however its not working for me: http://social.msdn.microsoft.com/Forums/en-US/74d9affc-ebf3-485c-988e-f28f7049b600/how-to-make-one-of-the-chart-ignore-series-grouping
Any help is as always appreciated.
The process described in that link should be OK.
Say I have some sample data:
And a simple chart that has the same issue you're describing:
Under the Network_count Chart Series properties, change the Value field expression to:
=Sum(Fields!Network_count.Value, "Month_CategoryGroup")
Here, Month_CategoryGroup is the name of a Category Group:
Now the Network_count value is the total for all Locations:
You'll note I've removed Network_count from the Legend:
This was displaying incorrectly so I just removed it. If you still want a Legend, the easiest thing would be to create something with a tablix/textboxes outside of the chart.

Color chart bars depending on category group value

I have the following chart (ssrs 2008), it shows sales according to #FromDate and #ToDate parameters.
The data is correct.
The problem is that when it shows comparison between years (=more than one year for the same month on a chart), the color stays the same, as you can see in months 4, 5, 6, 7:
How can i change it?
I would appreciate your help
There are a few different web descriptions with overviews of controlling the bar colors in a chart, such as this at learn.microsoft.com or Change the series colors for a bar chart (Images are currently dead in this, limiting its helpfulness).
The key is finding the "Series Properties" dialog and the "Fill" section, where you can specify the fill color: Use an expression such as:
=IIF(YEAR(Fields!MyDateField.Value) mod 2 = 0, "#FF0000", "#00FF00")
To Add some more explanation to JamieFs answer. This is the steps that I followed:
Right click on the series Select "Series Properites..."
Go to Fill:
Press the Expression button(Fx) and type in your equation to calculate the colour: