Ignore date gaps (e.g. financial dates)

742 views
Skip to first unread message

Teliac

unread,
Jun 11, 2012, 1:37:57 PM6/11/12
to google-visua...@googlegroups.com
I have a line chart which plots portfolio value against the date.  The dates in the data set are only market dates - no weekends or holidays.  However when the chart is drawn, it draws a long gap between two consecutive market days that cover a weekend or holiday (from a Friday to a Monday, for example).  Is there a way to show the Friday to Monday as a single, one day gap rather than the three day gap the chart currently draws?

I have been using Google Vis for a while, and I believe this desired behavior was previously supported but I have not been able to find other discussions on this.

I do not want to use he annotated timeline for a variety of reasons, and it is important for me to keep the horizontal axis as a JavaScript date type for client side manipulation purposes.

Thanks,

Teliac

asgallant

unread,
Jun 11, 2012, 2:22:08 PM6/11/12
to google-visua...@googlegroups.com
I'm assuming you need the dates in the DataTable to do data manipulation, but they don't have to be date objects by the time they get to the chart.  Use a DataView to convert the dates to strings and draw the chart based on the view - this will make the chart draw with a discrete axis instead of a continuous axis, which will fix the problem for you.

Teliac

unread,
Jun 11, 2012, 3:59:30 PM6/11/12
to google-visua...@googlegroups.com
Thank you for the idea.  My chart is displayed via a ChartWrapper object as presented here:

    var cw = new google.visualization.ChartWrapper();
    cw.setDataTable(dt);
    cw.setChartType(chartType);
    cw.setContainerId(divID);
    cw.setOptions(cc_options);
    cw.setView({columns: options[page].visibleColumns});
    cw.draw();

Is there a way to set the column type via the ChartWrapper, or do I need to go through the DataView directly?

asgallant

unread,
Jun 11, 2012, 5:30:27 PM6/11/12
to google-visua...@googlegroups.com
Normally, I would suggest using the ChartWrapper's 'view' option (what you are accessing through the setView method), but since you are getting entering a column list from somewhere else already, I will present an alternative as well.

Method 1: set the 'view' option
// assumes you used a DateFormat (or other) formatter on the date column already
var columns [];
columns.push({
    type'string',
    labeldata.getColumnLabel(options[page].visibleColumns[0]),
    calcfunction (dtrow{
        // if you didn't format already, you can do it here (get raw date with the #getValue method instead)
        return dt.getFormattedValue(rowoptions[page].visibleColumns[0]);
    }
});
// add in the rest of the columns
for (var 1options[page].visibleColumns.lengthi++{
    columns.push(options[page].visibleColumns[i]);
}
cw.setView({columnscolumns}); 

Method 2: create a view object to drive the chart
// in this view, EVERY column in the DataTable in included, in order
var view new google.visualization.DataView(data);
view.setColumns([
    /* list of columns preceeding date column */
    {
        ​type'string',
        ​labeldata.getColumnLabel(indexOfDateColumn),
        calcfunction (dtrow{
            return dt.getFormattedValue(rowindexOfDateColumn);
        }
    }
    /* list of columns following date column */
]);
cw.setDataTable(view);

Jim Schoettler

unread,
Jun 12, 2012, 3:40:12 AM6/12/12
to google-visua...@googlegroups.com
That is very helpful...  Thank you for both suggestions.  I do not completely follow the "row" argument (appearing in both approaches).  I understand that it refers to a row index... but is "row" a reserved term in the API such that the function interprets each row in turn, or does "row" require a specific initialization elsewhere?

Again, thank you for your time on this.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/76ryLs2OO-YJ.

To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.

asgallant

unread,
Jun 12, 2012, 11:19:51 AM6/12/12
to google-visua...@googlegroups.com
Are you referring to "row" here:

calcfunction (dtrow{ 

?

If so, there is nothing special about the term.  The 'calc' refers to a function which takes two arguments: a DataTable object and a row index.  The function is called once for every row and is used to calculate a return value for that column.

The variable names I chose are arbitrary - anything would do there, as long as you don't reuse a variable that is already in scope (ie, I couldn't use: "calcfunction (dt, columns{" because columns is a variable I already have in use in the same scope).  

To post to this group, send email to google-visualization-api@googlegroups.com.
To unsubscribe from this group, send email to google-visualization-api+unsub...@googlegroups.com.

asgallant

unread,
Jun 14, 2012, 10:12:49 AM6/14/12
to google-visua...@googlegroups.com
I don't believe you can in the Annotated Timeline charts.  With standard line charts using the "annotation" and "annotationText" column roles and augmented by a ChartRangeFilter, you can build something that has most of the functionality of the ATL charts.

On Wednesday, June 13, 2012 1:42:25 PM UTC-4, General Charter wrote:
May I ask how I may do this (skip gaps in 'date' x-axis) if I am using the AnnotatedTimeLine?

Thanks in advance!

vlad

unread,
Jul 27, 2017, 12:15:24 PM7/27/17
to Google Visualization API
I have just came across a similar issue.  My data is effectively a time series that does not have any values on Weekends & holidays.

I could, as @asgallant suggested, convert my dates to strings and be happy.  However, the users would like to Zoom into my data, which appears to only work on continuous axes.

The alternative I am considering is using a sequence (1..N) for each of the Dates and displaying the Date values in place of the order numbers.  But I am not sure how to configure that.

I am happy to either use the index of row or create another column with just numbers in DataTable and reference to dates from DataView.  The Date text must be displayed on both, hAxis and Popup Tooltips over data points.

Any suggestions on how to do that?

Thanks,

- vlad

Alphatrade Asset Management LLC

unread,
Apr 15, 2018, 7:21:06 AM4/15/18
to Google Visualization API
yes, please add an option to exclude "holes" in the data!

i've some charts which currently are looking like this and those gaps just kinda alter reality...

 






thank you so much!

best,
Andreas
Reply all
Reply to author
Forward
0 new messages