jossetter
jossetter

Reputation: 188

Google Chart - Timelines: Scaling Axis

I'm trying to create a chart using Google's Timeline that shows activity over the last 7 days, and I'm running into problems with scaling the x-axis.

The chart is always trying to auto-scale to the data, which ruins the consistency I'd like to incorporate. I want the right side of the graph to be today's date, and the left side to be seven days before today's date.

I can't seem to find anything for fixing the x-axis in the documentation for Timelines or even Visualization in general, but I have to believe a charting library has the ability to configure its own axes. Does anyone have a solution that works?

A possible workaround I have is creating two data points -- one for today and one for today-7 -- and add them to the graph. This fixes the scaling problem, but now my graph has two arbitrary data points on it. (I know it's technically a separate question, but if anyone knows how to hide these two data points while still maintaining the fixed axis scale that'd be a win!)

Here's what my graph looks like using just the raw data (notice the axis -- I would like this to be last 7 days):axis auto-scaled

And here's what it looks like with my two 'faked' data points:axis fixed-scaled, but two bad data points

EDIT: I have tried using the viewWindow.max and viewWindow.min properties, but it doesn't seem to be working.

Upvotes: 4

Views: 869

Answers (2)

Ryan
Ryan

Reputation: 24462

hAxis.minValue and hAxis.maxValue will do this.

e.g.

var options = {
   hAxis: {
      minValue : new Date(2024,11,24),
      maxValue : new Date(2024,12,1),
   }
}
chart.draw(dataTable, options)

Upvotes: 0

Bing
Bing

Reputation: 27

I think you can white out the two dummy points by using options like:

  var options = {
    colors: ['#ffffff', '#ffffff', '#c69c6e'],
  };

Upvotes: 0

Related Questions