How do I change the Horizontal Axis labels for a line chart in Google Charts?

19,976

To get the required output as in your link try this code.

            var dataTable = new google.visualization.DataTable();
            dataTable.addColumn('date', 'Date');
            dataTable.addColumn('number', 'Example1');
            dataTable.addColumn('number', 'Example2');
            dataTable.addColumn('number', 'Example3');
            dataTable.addColumn('number', 'Example4');
            dataTable.addColumn('number', 'Example5');
            dataTable.addColumn('number', 'Example6');

            dataTable.addRows([
          [new Date(2013, 5, 28), 2, 3, 4, 5, 6, 7],
          [new Date(2013, 6, 22), 7, 8, 9, 6, 10, 14],

        ]);

           var options = {
                title: 'Average Ratings',
                vAxis: { title: "Average Rating" },
                legend:{position:'top',alignment:'start'},
                hAxis: {
                    title: "Date",
                    gridlines: { count: 3, color: '#CCC' },
                    format: 'dd-MMM-yyyy'
                }
            };

Take a look at this jqfaq.com. It has the working sample.

Share:
19,976

Related videos on Youtube

Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I am trying to create a line chart in google docs, I want to have the horizontal axis separated into dates with weekly intervals, I cant seem to find where to set the labels for the horizontal axis. I'm happy with everything else so far but the labels don't match up with the data I have. They are also divided into weekly intervals but not the dates I want. Here is a link to an example https://docs.google.com/spreadsheet/ccc?key=0AmBbC6c2eCrHdHU3d3lVMTlUYkRpMVFISE9KX1RET1E&usp=sharing All the data for the chart is on the Average ratings figure tab, and the chart is on the Summary tab. Any help would be greatly appreciated. Thanks :)

  • Rafael Santos
    Rafael Santos over 2 years
    Just to let an admin know, the jqfaq.com site seems to redirect to one of those take "you got a virus" scam sites.