customizing the x-axis range for dates in a LineChart

494 views
Skip to first unread message

gaëlle fernandez

unread,
Feb 28, 2012, 12:52:27 PM2/28/12
to Google Visualization API
Hi everybody!
(first of all, excuse my bad english, i'm a beginner)

i want to draw a linechart of percent by dates (percent in y and dates
in x axis)
i want to symbolize each week of a current month by just display each
monday of each week.
(all of these mondays are stocked into a array called mondays[].)

so, my chart will have just 4 or 5 visible dates on the x-axis.

i tried to work with the chxr parameter by changing it in the options
here is how i set my columns :

var chartTimeLine = new google.visualization.DataTable();
chartTimeLine.addColumn('date', 'Temps');
chartTimeLine.addColumn('number','Fréquence');
for (var j=0;j<mesFreq.length;j++){
chartTimeLine.addRows([
[mondays[j],mesFreq[j]]
])
}

var myOptions = {
axis_index:0,
start_val:mondays[0],
end_val:mondays[mondays.length-1],
opt_step:mondays.length/2
}

var chartLine = new google.visualization.LineChart(myDiv);
chartLine.draw(chartTimeLine, myOptions);

so, my result shows me a chart with several dates of my current month
and not just the four mondays i would like to display.

Do you have any idea on what is the problem and how i can fix it,
please?

(and i don't want to use an annotated time line)

Thanks!

asgallant

unread,
Feb 28, 2012, 3:28:07 PM2/28/12
to google-visua...@googlegroups.com
If you want only the Mondays to show up, you'll need to set the type of the first column to 'string' not 'date'.  Type 'date' produces a continuous axis (a timeline, in this case), so the displayed axis values need not line up with specific data points; type 'string' produces a discrete axis where every point has it's own axis label.  You could, using a string type, simply set each value to the month instead of a date (ie, 'January', 'February', 'March', etc).

I should also point out that you don't have any valid options in your options array; see the list of available options here: http://code.google.com/apis/chart/interactive/docs/gallery/linechart.html#Configuration_Options 

gaëlle fernandez

unread,
Feb 29, 2012, 4:02:22 AM2/29/12
to Google Visualization API
Well, thank you asgallant, you helped me a lot! :)
Now i just have to show the lines, only for a readable comfort.
thank you very much , problem fixed!


On 28 fév, 21:28, asgallant <drew_gall...@abtassoc.com> wrote:
> If you want only the Mondays to show up, you'll need to set the type of the
> first column to 'string' not 'date'.  Type 'date' produces a continuous
> axis (a timeline, in this case), so the displayed axis values need not line
> up with specific data points; type 'string' produces a discrete axis where
> every point has it's own axis label.  You could, using a string type,
> simply set each value to the month instead of a date (ie, 'January',
> 'February', 'March', etc).
>
> I should also point out that you don't have any valid options in your
> options array; see the list of available options here:http://code.google.com/apis/chart/interactive/docs/gallery/linechart....
Reply all
Reply to author
Forward
0 new messages