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.
Related
since I started to use Power BI for my weekly reports, I was not able to resolve the following issue.
Most of my charts are on a weekly basis, so for example a chart of the last 13 weeks will have the following weeks as x-axis values: 47, 48, 49, 50, 51, 52, 1, 2, 3, 4, 5, 6, and 7.
The problem in this case is, that if I sort it by week, Power BI will always sort the values like this: 1, 2, 3, 4, 5, 6, 7, 47, 48, 49, 50, 51, 52. This is obviously wrong because week 1 of the following year should be placed after week 52 of the previous year.
So I came to the following solution: I concatenated the year value with the week value, so the values look like this: ..., 202151, 202152, 202201, 202202, ...
This solved at least my sorting issue. The graphs are displayed in the correct chronological order.
But there is one problem with this solution: The six-digit values are just way to huge and it is very hard for the reader to differ between the weeks.
too large markers
I would like to have only the 2-digit week number displayed on the x-axis, but still keep the sorting properly over the change of a year.
I hope someone has solved this. Thank you in advance!
Configure YearWeek as the "sort by column" for WeekNumber, and switch the X-Axis type to "Categorical" on your Bar Chart
or Line Chart
Perhaps you can use small multiples:
Rough steps:
Create a columns chart
In the Axis field place your week number column
In the Values field place your column containing the values
In the Small multiples field place the year column
Format your visual such that the Small multiple grid has 1 row, but multiple columns.
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 :)
I need to build a DataFrame with a very specific structure. Yield curve values as the data, a single date as the index, and days to maturity as the column names.
In[1]: yield_data # list of size 38, with yield values
Out[1]:
[0.096651956137087325,
0.0927199778042056,
0.090000225505577847,
0.088300016028163508,...
In[2]: maturity_data # list of size 38, with days until maturity
Out[2]:
[6,
29,
49,
70,...
In[3]: today
Out[3]:
Timestamp('2017-07-24 00:00:00')
Then I try to create the DataFrame
pd.DataFrame(data=yield_data, index=[today], columns=maturity_data)
but it returns the error
ValueError: Shape of passed values is (1, 38), indices imply (38, 1)
I tried using the transpose of these lists, but it does not allow to transpose them.
how can I create this DataFrame?
IIUC, I think you want a dataframe with a single row, you need to reshape your data input list into a list of list.
yield_data = [0.09,0.092, 0.091]
maturity_data = [6,10,15]
today = pd.to_datetime('2017-07-25')
pd.DataFrame(data=[yield_data],index=[today],columns=maturity_data)
Output:
6 10 15
2017-07-25 0.09 0.092 0.091
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:
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}