I have a line chart which the dark blue line data point ends halfway through the chart, as no future data is yet available.
Is there a way to continue the line throughout the rest of the months on the date X Axis as a straight line with its current end position?
Current measure reads
Actuals = SELECTEDVALUE('Actual Hours'[Average Actual FTE])
Chart
Dataset
EDIT
Updated Line Chart
New Measure Code
To continue the line you should fill blanks for future dates like this:
Actuals =
VAR _LastDate =
CALCULATE(
MAX('Table'[month]),
ALL('Table'),
NOT(ISBLANK('Table'[value]))
)
VAR _Value =
CALCULATE(
SUM('Table'[value]),
'Table'[month] = _LastDate
)
RETURN
SWITCH(
SUM('Table'[value]),
BLANK(), _Value,
SUM('Table'[value])
)
_LastDate defines last date with non-blank value and _Value gets value for this date. Inside RETURN we fill blanks with _Value and do nothing to non-blanks.
On my dummy data it looks like:
Related
I have this:
But I want the x axis to run along y=0, e.g.
And ideally I'd either have the tick labels on top i.e. in the blue bit, or where they were at the bottom of the chart.
EDIT: how the chart is created.
I'm using something like:
var
ndx = crossfilter(data),
dataDimension = ndx.dimension(d => d.period),
ordinals = data.map(d => d.period),
lossGroup = dataDimension.group().reduceSum(d => d.loss),
offsets = lossGroup.all().map(d => -d.value),
chart;
// The data is like {
// period: Date (start of period, e.g. month),
// start: Integer (number at start of period/end of last period)
// loss: Integer (number lost during period)
// gain: Integer (number gained during period)
// }
chart = dc.barChart(chartElement)
.dimension(dataDimension)
// The first group is the loss
.group(lossGroup)
.stack(dataDimension.group().reduceSum(d => d.start), 'carryforward')
.stack(dataDimension.group().reduceSum(d => d.gain), 'gain')
.stackLayout(d3.layout.stack().offset(layers => offsets))
.x(d3.scale.ordinal(ordinals).domain(ordinals))
.xUnits(dc.units.ordinal)
.elasticY(true)
.renderLabel(false)
// The first group is the loss
.title(item => 'Loss: ' + item.value)
.title('carryforward', item => 'Sustained: ' + item.value)
.title('gain', item => 'Gain: ' + item.value)
.renderTitle(true);
dc.renderAll();
Hmm, I guess you are using .stackLayout() to get the negative stacking. Since dc.js doesn't “look inside” this setting, I don't think there is anything built-in to offset the axis. You would probably need to use a pretransition handler to move it.
As for moving the tick labels, you could use .title() instead, like in this example. And then set the tick label to empty.
Best I can think of, not really an answer but more than a comment. :-)
I attempt to show a tersely formatted date/time on the x-axis in a graphview chart. As per the API Code examples, I set HumanRounding to false when using using a date formatter on that axis. I'm also setting the NumHorizontalLabels to 3 in order to display reasonably OK in both orientations.
This results in e.g. the following, where the date labels show as a black shape, and the LineChart background is different. I'm speculating that the black shape is the result of all my date data points overwriting each other:
With HumanRounding set to true (commented out), I get labels showing, but instead of the expected 3 evenly distributed labels, they are unpredictably spread out and/or not equal to 3, sometimes the labels over-write each other, sometimes they are bunched on the left...
The number of date data-points on the x-axis can vary depending on how much history the user has selected. Note that this can vary from 60 to thousands of minutes.
Here's the code that receives data and charts it. Note that the unixdate retrieved from wxList elements has already been converted to a Java date (by multiplying by 1000) by the time they get used here (the time portion of the x-axis are in fact correct when they do show up in a reasonably distributed manner):
protected void onPostExecute(List<WxData> wxList) {
// We will display MM/dd HH:mm on the x-axes on all graphs...
SimpleDateFormat shortDateTime = new SimpleDateFormat("MM/dd HH:mm");
shortDateTime.setTimeZone(TimeZone.getTimeZone("America/Toronto"));
DateAsXAxisLabelFormatter xAxisFormat = new DateAsXAxisLabelFormatter(parentContext, shortDateTime);
if (wxList == null || wxList.isEmpty()) {
makeText(parentContext,
"Could not retrieve data from server",
Toast.LENGTH_LONG).show();
} else {
// Temperature Celcius
GraphView tempGraph = findViewById(R.id.temp_graph);
tempGraph.removeAllSeries();
tempGraph.setTitle(parentContext.getString(R.string.temp_graph_label));
DataPoint[] tempCArray = new DataPoint[wxList.size()];
for (int i = 0; i < wxList.size(); i++) {
tempCArray[i] = new DataPoint(wxList.get(i).getUnixtime(), wxList.get(i).getTempC().doubleValue());
}
LineGraphSeries<DataPoint> tempCSeries = new LineGraphSeries<>(tempCArray);
tempGraph.addSeries(tempCSeries);
tempGraph.getGridLabelRenderer().invalidate(false, false);
tempGraph.getGridLabelRenderer().setLabelFormatter(xAxisFormat);
tempGraph.getGridLabelRenderer().setNumHorizontalLabels(3);
tempGraph.getViewport().setMinX(wxList.get(0).getUnixtime());
tempGraph.getViewport().setMaxX(wxList.get(wxList.size() - 1).getUnixtime());
tempGraph.getViewport().setXAxisBoundsManual(true);
// Code below seems buggy - with humanRounding, X-axis turns black
// tempGraph.getGridLabelRenderer().setHumanRounding(false);
...
I have tried many variations,but I cannot get the graph to consistently display 3 datetimes evenly spread out, for both orientations, for varyings sample sizes. Any help is appreciated.
I've done some reading but my limited knowledge on scripts is making things difficult. I want to:
Copy a variable number of rows data range, known colums, from one sheet titled 'Download'
Paste that data in a new sheet titled 'Trade History' from Column B
In the new sheet, add today's date formatted (DD/MM/YYYY) in a new column A for each record copied
The data in worksheet 'Download' uses IMPORTHTML
The data copied from Download to store a historical record needs a date in Column A
I've managed to get 1 and 2 working, but can't work out the 3rd. See current script below.
function recordHistory() {
var ss = SpreadsheetApp.getActive(),
sheet = ss.getSheetByName('Trade_History');
var source = sheet.getRange("a2:E2000");
ss.getSheetByName('Download').getRange('A2:E5000').copyTo(sheet.getRange(sheet.getLastRow()+1, 2))
}
You need to use Utilities.formatDate() to format today's date to DD/MM/YYYY.
Because you're copying one set of values, and then next to it (in column A), pasting another, I altered your code a bit as well.
function recordHistory() {
var ss = SpreadsheetApp.getActive(),
destinationSheet = ss.getSheetByName('Trade_History');
var sourceData = ss.getSheetByName('Download').getDataRange().getValues();
for (var i=0; i<sourceData.length; i++) {
var row = sourceData[i];
var today = Utilities.formatDate(new Date(), 'GMT+10', 'dd/MM/yyyy'); // AEST is GMT+10
row.unshift(today); // Places data at the beginning of the row array
}
destinationSheet.getRange(destinationSheet.getLastRow()+1, // Append to existing data
1, // Start at Column A
sourceData.length, // Number of new rows to be added (determined from source data)
sourceData[0].length // Number of new columns to be added (determined from source data)
).setValues(sourceData); // Printe the values
}
Start by getting the values of the source data. This returns an array that can be looped through to add today's date. Once the date has been added to all of the source data, determine the range boundaries for where it will be printed. Rather than simply selecting the start cell as could be done with the copyTo() method, the full dimensions now have to be defined. Finally, print the values to the defined range.
I have an SSRS report with a matrix in it, where I needed to display the Growth Percentage in a column group compared to the previous column value. I managed this by using custom code...
DIM PreviousColValue AS Decimal
Dim RowName AS String = ""
Public Function GetPreviousColValue(byval Val as Decimal, byval rwName as string) as Decimal
DIM Local_PreviousColValue AS Decimal
IF RowName <> rwName THEN
RowName = rwName
PreviousColValue = val
Local_PreviousColValue = 0
ELSE
Local_PreviousColValue = (Val - PreviousColValue)/PreviousColValue
PreviousColValue = val
END IF
Return Local_PreviousColValue
End Function
..and then using this as the value expression in the cell..
=Round(Code.GetPreviousColValue(ReportItems!Textbox8.Value,Fields!BusinessUnit.Value)*100,0,system.MidpointRounding.AwayFromZero)
So far so good, this produces the expected value. Now I need to use this expression in a background color expression to get a red/yellow/green but in that capacity it fails.
The background color expression looks like this: =IIF(ROUND(Code.GetPreviousColValue(ReportItems!Textbox9.Value,Fields!Salesperson.Value)*100,0,System.MidpointRounding.AwayFromZero)<=-5,"Red"
,IIF(ROUND(Code.GetPreviousColValue(ReportItems!Textbox9.Value,Fields!Salesperson.Value)*100,0,System.MidpointRounding.AwayFromZero) >=5,"Green"
,"Yellow"))
When I run the report the background color expression only ever returns yellow. As a test I pasted the background color expression in as the cell value and ran it again. Results in the image below
I get no build or run time errors so I'm not sure why this does not work.
After some more searching I found a better Custom Code solution than what I was using to get the Growth Percentage in a column group compared to the previous column value. Besides being simpler to read this version has an added benefit: You can dynamically hide the growth percentage column for your first instance of the column group (because it will always be zero or null) and still get the right values in the 2nd/3rd/4th instance of the column group.
Public Function GetDeltaPercentage(ByVal PreviousValue, ByVal CurrentValue) As Object
If IsNothing(PreviousValue) OR IsNothing(CurrentValue) Then
Return Nothing
Else if PreviousValue = 0 OR CurrentValue = 0 Then
Return Nothing
Else
Return (CurrentValue - PreviousValue) / PreviousValue
End If
End Function
The new function is called like so
=Code.GetDeltaPercentage(Previous(Sum(<expression or dataset field>),"Group ByColumn"), Sum(<expression or dataset field>))
Re: the original question - why does my cell value expression not work when used as the background color expression - I took an easy out and just referenced the cell value.
=IIF(ROUND(Me.Value*100,0,System.MidpointRounding.AwayFromZero)<=-5,"Red"
,IIF(ROUND(Me.Value*100,0,System.MidpointRounding.AwayFromZero) >=5,"Green"
,"Yellow"))
There is a Spreadsheet with two columns: Date, Integer. And some rows are missing.
When I insert chart manually, I see long horizontal line instead of missing rows.
But when I do this:
var sheet = SpreadsheetApp.openById(id).getSheets()[0];
var table = Charts.newDataTable().
addColumn(Charts.ColumnType.STRING, "Date").
addColumn(Charts.ColumnType.NUMBER, "asd");
sheet.getSheetValues(sheet.getLastRow() - 9, 1, 10, 2).forEach( function(line) {
var date = new Date(line[0]);
table.addRow( [
date.getDate() + " " + ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][date.getMonth()],
line[1]
] );
} );
var chart = Charts.newLineChart().
setDataTable(table).
setXAxisTitle("Date").
setYAxisTitle("asd").
setTitle("asd").
build();
var temp = "<img src=\'cid:asd\'/>";
MailApp.sendEmail("asd#gmail.com", "asd", temp, {
htmlBody: temp,
inlineImages: { asd: chart }
} );
the X axis is collapsed, because its values aren't actually Dates, because I reformatted them.
(red lines were made in mspaint to focus your attention)
What is a proper way to make it with horizontal line, like in Spreadsheet, and with customly formatted Dates, like in the image from email?
Whenever you do this it will take the regular behavior in this case make the connection between available values.
If you change the type of chart, it would illustrate missing values more appropriately; bars or other type of charts would illustrate in a better way missing values.