Google chart can you split up array in another way? - google-visualization

As far as I have seen it this is the way to make a line chart is like this in Google Charts:
data.addRows(
[
// change strings to Dates (year, month), where months are zero-indexed
[new Date(2013, 0), 5, 2, 1],
[new Date(2012, 11), 2, 0, 2],
[new Date(2012, 10), 5, 1, 3]
]);
The above will make three lines.....line 1: 5->2->5, line 2: 2->0->1 and line 3: 1->2->3. This is not logical for me. I would like to make a line like this....line 1:
data.addRows(
[
// change strings to Dates (year, month), where months are zero-indexed
[new Date(2013, 0), 5],
[new Date(2012, 11), 2],
[new Date(2012, 10), 5]
]);
And then line 2:
data.addRows(
[
// change strings to Dates (year, month), where months are zero-indexed
[new Date(2013, 0), 2],
[new Date(2012, 11), 0],
[new Date(2012, 10), 1]
]);
etc. My example is wrong. But I hope you get what I mean to do - and you can find a way to make a more DB-friendly query. The reason is also that my dates will differ. So I would need a long array with lots of nulls in it.
Well I hope you can help me :)

Related

Previous Week Dates using Power Query M in Power Bi

I'm using code from Chris Webb:
Source
and here is the sample code from his site:
Ranges = {
{"Today",
TodaysDate,
TodaysDate,
1},
{"Current Week To Date",
Date.From(Date.StartOfWeek(TodaysDate)),
TodaysDate,
2},
{"Current Month To Date",
Date.From(Date.StartOfMonth(TodaysDate)),
TodaysDate,
3},
{"Current Year To Date",
Date.From(Date.StartOfYear(TodaysDate)),
TodaysDate,
4},
.......
I'm looking to get the previous week dates. I tried:
{"Previous Week",
dates.AddWeeks(Date.From(Date.StartOfWeek(TodaysDate,Day.Thursday)),-1),
TodaysDate,
4},
Which works but of course it also adds the dates for the current week (which is Thursday to Thursday in my case). Any ideas about only getting the previous week based on this method? Possibly subtracting the dates from the current week and previous week?
I'm not trying to do week flags or use DAX or R. Preferably in this format.
Anything would help!!! Thanks!
I figured it out.
Here is my final code if anyone is looking for something like this.
It includes Yesterday and Previous Week with a custom week start date. I'm new at this so I guess that's my excuse for it being right in front of me and me missing it!
= {
{"Today",
TodaysDate,
TodaysDate,
1},
{"Yesterday",
Date.AddDays(TodaysDate,-1),
Date.AddDays(TodaysDate,-1),
2},
{"Week to Date",
Date.From(Date.StartOfWeek(TodaysDate,Day.Thursday)),
TodaysDate,
3},
{"Previous Week",
Date.AddWeeks( Date.From(Date.StartOfWeek(TodaysDate,Day.Thursday)),-1),
Date.From(Date.StartOfWeek(TodaysDate,Day.Thursday)),
4},
{"Current Month To Date",
Date.From(Date.StartOfMonth(TodaysDate)),
TodaysDate,
5},
{"Current Year To Date",
Date.From(Date.StartOfYear(TodaysDate)),
TodaysDate,
6},
{"Rolling 13Weeks",
Date.AddWeeks(TodaysDate,-13) + #duration(1,0,0,0),
TodaysDate,
7}
}

How to dynamic filter on Power BI?

How can I make a dynamic filter on a Power BI chart?
I have a MONTH table and it contains these values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12. I do not want to display data for months that are bigger than the current month, MONTH(TODAY()).
I want something like this:
You can set up a measure instead to determine whether to show the particular month or not as follows:
Show = IF(FIRSTNONBLANK('Month'[Month], 13) <= MONTH(TODAY()), 1, 0)
And then you can add this measure to Visual level filters and set it equal to 1.
Results:

Google Chart API: Graphing line charts with different set of x-axis

I want to graph two line charts in Google API. The line charts are voltage over time. The problem is the sampling for these two charts is done at different intervals, e.g.
Line 1 Line 2
0s - 1V 0s - 2V
2s - 3V 1s - 2V
5s - 3.4V 2s - 2.3V
10s - 3V 7s - 4V
11s - 2.1V
From the Google Charts API, I gathered that the x-axis array has to be shared between the y-axis charts. How can I go about graphing these two lines, when their x-axis is different, and they might have a different number of data points.
You need to add both data series to your DataTable, filling in null where one data series does not have data at a particular x-axis value:
var data = new google.visualization.DataTable();
data.addColumn('number', 'Seconds');
data.addColumn('number', 'Line 1');
data.addColumn('number', 'Line 2');
data.addRows([
[0, 1, 2],
[1, null, 2],
[2, 3, 2.3],
[5, 3.4, null],
[7, null, 4],
[10, 3, null],
[11, 2.1, null],
]);
The nulls will insert gaps in your lines, which you can close by setting the interpolateNulls option to true.

Google Charts Line graph displaying only first and last label

I have a line graph and the X-axis comprises of dates. what I want to do is that, my chart should display only the first-date and the last-date on the axis with sufficient gap in between to display the data related to the other dates (but NOT the label)
eg- http://i.stack.imgur.com/ujSRu.png
You need to set the hAxis.ticks option:
hAxis: {
// set the x-axis to show dates at each end, Oct 27 2013 - Nov 18 2013
// with no tick marks or labels in between
ticks: [new Date(2013, 9, 27), new Date(2013, 10, 18)]
}
If you know the exact amount of data entries, you may do:
hAxis: {showTextEvery: 4}

Formatting google chart area date( like Mar 2012, Oct 2013 etc)

I want to show Google Chart Area date as Mar 2012, Oct 2013 etc. There should not be any date digits in the format. I can only find 3 formats as
formats
var formatter_long = new google.visualization.DateFormat({formatType: 'long'});
var formatter_medium = new google.visualization.DateFormat({formatType: 'medium'});
var formatter_short = new google.visualization.DateFormat({formatType: 'short'});
Resulting in to
February 28, 2008 (long)
Feb 28, 2008 (medium)
2/28/08 (short)
long and medium work for me if I can remove date digits from the result. Is there a chance to do it somehow?
Google uses a subset of the ICU SimpleDateFormat standard.
If you mean "remove date digits" as in "remove the day and display just month/year" then you could format the string as follows:
function drawVisualization() {
// Create and populate the data table.
var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addRows([
[new Date(2012,1,5)],
[new Date(2012,2,10)],
[new Date(2012,3,15)],
[new Date(2012,4,20)]
]);
alert(data.getFormattedValue(3,0));
var formatter1 = new google.visualization.DateFormat({pattern: 'yyyy, MMM'});
formatter1.format(data,0);
alert(data.getFormattedValue(3,0));
}
When you define the data table, the first alert will list the formatted date as "May 20, 2012". Once you apply the formatter, it will read "May, 2012" only. I think this is what you want. You can change the format as desired.