Google Charts X Axis Showing Up Down Values











up vote
1
down vote

favorite












I have plotted a Google Line chart which is showing X axis values in alternating up down format when having more values as shown below.



enter image description here



But I want to show it in a single line in a much better representation than the current one, a slope representation would also be fine like below.



enter image description here



My code for plotting the chart is as below:



var options = {
width: '100%',
height: '100%',
legend: ({ position: 'top', maxLines: 1, alignment: 'end'}),
chartArea: { left: "8%", right: "8%", top: "10%", width: "100%", height: "75%" },
backgroundColor: 'transparent',
tooltip: { textStyle: { color: 'black' }, isHtml: true },
curveType: 'none',
};

var chart = new google.visualization.LineChart($('Div')[0]);
chart.draw(view, options);


Is there any specific option that I have to apply to make the axis display in the required format?










share|improve this question


























    up vote
    1
    down vote

    favorite












    I have plotted a Google Line chart which is showing X axis values in alternating up down format when having more values as shown below.



    enter image description here



    But I want to show it in a single line in a much better representation than the current one, a slope representation would also be fine like below.



    enter image description here



    My code for plotting the chart is as below:



    var options = {
    width: '100%',
    height: '100%',
    legend: ({ position: 'top', maxLines: 1, alignment: 'end'}),
    chartArea: { left: "8%", right: "8%", top: "10%", width: "100%", height: "75%" },
    backgroundColor: 'transparent',
    tooltip: { textStyle: { color: 'black' }, isHtml: true },
    curveType: 'none',
    };

    var chart = new google.visualization.LineChart($('Div')[0]);
    chart.draw(view, options);


    Is there any specific option that I have to apply to make the axis display in the required format?










    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have plotted a Google Line chart which is showing X axis values in alternating up down format when having more values as shown below.



      enter image description here



      But I want to show it in a single line in a much better representation than the current one, a slope representation would also be fine like below.



      enter image description here



      My code for plotting the chart is as below:



      var options = {
      width: '100%',
      height: '100%',
      legend: ({ position: 'top', maxLines: 1, alignment: 'end'}),
      chartArea: { left: "8%", right: "8%", top: "10%", width: "100%", height: "75%" },
      backgroundColor: 'transparent',
      tooltip: { textStyle: { color: 'black' }, isHtml: true },
      curveType: 'none',
      };

      var chart = new google.visualization.LineChart($('Div')[0]);
      chart.draw(view, options);


      Is there any specific option that I have to apply to make the axis display in the required format?










      share|improve this question













      I have plotted a Google Line chart which is showing X axis values in alternating up down format when having more values as shown below.



      enter image description here



      But I want to show it in a single line in a much better representation than the current one, a slope representation would also be fine like below.



      enter image description here



      My code for plotting the chart is as below:



      var options = {
      width: '100%',
      height: '100%',
      legend: ({ position: 'top', maxLines: 1, alignment: 'end'}),
      chartArea: { left: "8%", right: "8%", top: "10%", width: "100%", height: "75%" },
      backgroundColor: 'transparent',
      tooltip: { textStyle: { color: 'black' }, isHtml: true },
      curveType: 'none',
      };

      var chart = new google.visualization.LineChart($('Div')[0]);
      chart.draw(view, options);


      Is there any specific option that I have to apply to make the axis display in the required format?







      javascript charts google-visualization google-chartwrapper






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 at 10:20









      Hitesh

      2,09762539




      2,09762539
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          see the configuration options for hAxis



          for a slope representation, use --> slantedText: true




          hAxis.slantedText - If true, draw the horizontal axis text at an angle, to help fit more text along the axis.




          to enforce one level of labels, use --> maxAlternation: 1




          hAxis.maxAlternation - Maximum number of levels of horizontal axis text. If axis text labels become too crowded, the server might shift neighboring labels up or down in order to fit labels closer together.




          to keep the labels from wrapping on two lines, use --> maxTextLines: 1




          maxTextLines - Maximum number of lines allowed for the text labels. Labels can span multiple lines if they are too long, and the number of lines is, by default, limited by the height of the available space.




          note: you may need to adjust chartArea.bottom to allow more room along the x-axis...



          see following working snippet...






          google.charts.load('current', {
          packages:['corechart']
          }).then(function () {
          var dateFormat = 'dd MMM';
          var formatDate = new google.visualization.DateFormat({
          pattern: dateFormat
          });

          var dataTable = new google.visualization.DataTable();
          dataTable.addColumn('string', 'X');
          dataTable.addColumn('number', 'Value');

          var oneDay = (1000 * 60 * 60 * 24);
          var startDate = new Date(2018, 9, 1);
          var endDate = new Date(2018, 9, 31);
          var ticksAxisH = ;
          for (var i = startDate.getTime(); i <= endDate.getTime(); i = i + oneDay) {
          var rowDate = new Date(i);
          var xValue = formatDate.formatValue(rowDate);
          var yValue = (2 * ((i - startDate.getTime()) / oneDay) + 8);
          dataTable.addRow([
          xValue,
          yValue
          ]);
          }

          var container = document.getElementById('chart_div');
          var chart = new google.visualization.LineChart(container);

          var options = {
          width: '100%',
          height: '100%',
          legend: {
          position: 'top',
          maxLines: 1,
          alignment: 'end'
          },
          chartArea: {
          bottom: 40,
          left: '8%',
          right: '8%',
          top: '10%',
          width: '100%',
          height: '75%'
          },
          backgroundColor: 'transparent',
          tooltip: {
          textStyle: {
          color: 'black'
          },
          isHtml: true
          },
          curveType: 'none',
          hAxis: {
          slantedText: true
          }
          };

          function drawChart() {
          chart.draw(dataTable, options);
          }

          drawChart();
          window.addEventListener('resize', drawChart, false);
          });

          <script src="https://www.gstatic.com/charts/loader.js"></script>
          <div id="chart_div"></div>








          share|improve this answer





















          • Thank you so much, this worked perfectly. Don't know how I missed this out in the documentation.
            – Hitesh
            Nov 21 at 11:42











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390836%2fgoogle-charts-x-axis-showing-up-down-values%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          see the configuration options for hAxis



          for a slope representation, use --> slantedText: true




          hAxis.slantedText - If true, draw the horizontal axis text at an angle, to help fit more text along the axis.




          to enforce one level of labels, use --> maxAlternation: 1




          hAxis.maxAlternation - Maximum number of levels of horizontal axis text. If axis text labels become too crowded, the server might shift neighboring labels up or down in order to fit labels closer together.




          to keep the labels from wrapping on two lines, use --> maxTextLines: 1




          maxTextLines - Maximum number of lines allowed for the text labels. Labels can span multiple lines if they are too long, and the number of lines is, by default, limited by the height of the available space.




          note: you may need to adjust chartArea.bottom to allow more room along the x-axis...



          see following working snippet...






          google.charts.load('current', {
          packages:['corechart']
          }).then(function () {
          var dateFormat = 'dd MMM';
          var formatDate = new google.visualization.DateFormat({
          pattern: dateFormat
          });

          var dataTable = new google.visualization.DataTable();
          dataTable.addColumn('string', 'X');
          dataTable.addColumn('number', 'Value');

          var oneDay = (1000 * 60 * 60 * 24);
          var startDate = new Date(2018, 9, 1);
          var endDate = new Date(2018, 9, 31);
          var ticksAxisH = ;
          for (var i = startDate.getTime(); i <= endDate.getTime(); i = i + oneDay) {
          var rowDate = new Date(i);
          var xValue = formatDate.formatValue(rowDate);
          var yValue = (2 * ((i - startDate.getTime()) / oneDay) + 8);
          dataTable.addRow([
          xValue,
          yValue
          ]);
          }

          var container = document.getElementById('chart_div');
          var chart = new google.visualization.LineChart(container);

          var options = {
          width: '100%',
          height: '100%',
          legend: {
          position: 'top',
          maxLines: 1,
          alignment: 'end'
          },
          chartArea: {
          bottom: 40,
          left: '8%',
          right: '8%',
          top: '10%',
          width: '100%',
          height: '75%'
          },
          backgroundColor: 'transparent',
          tooltip: {
          textStyle: {
          color: 'black'
          },
          isHtml: true
          },
          curveType: 'none',
          hAxis: {
          slantedText: true
          }
          };

          function drawChart() {
          chart.draw(dataTable, options);
          }

          drawChart();
          window.addEventListener('resize', drawChart, false);
          });

          <script src="https://www.gstatic.com/charts/loader.js"></script>
          <div id="chart_div"></div>








          share|improve this answer





















          • Thank you so much, this worked perfectly. Don't know how I missed this out in the documentation.
            – Hitesh
            Nov 21 at 11:42















          up vote
          2
          down vote



          accepted










          see the configuration options for hAxis



          for a slope representation, use --> slantedText: true




          hAxis.slantedText - If true, draw the horizontal axis text at an angle, to help fit more text along the axis.




          to enforce one level of labels, use --> maxAlternation: 1




          hAxis.maxAlternation - Maximum number of levels of horizontal axis text. If axis text labels become too crowded, the server might shift neighboring labels up or down in order to fit labels closer together.




          to keep the labels from wrapping on two lines, use --> maxTextLines: 1




          maxTextLines - Maximum number of lines allowed for the text labels. Labels can span multiple lines if they are too long, and the number of lines is, by default, limited by the height of the available space.




          note: you may need to adjust chartArea.bottom to allow more room along the x-axis...



          see following working snippet...






          google.charts.load('current', {
          packages:['corechart']
          }).then(function () {
          var dateFormat = 'dd MMM';
          var formatDate = new google.visualization.DateFormat({
          pattern: dateFormat
          });

          var dataTable = new google.visualization.DataTable();
          dataTable.addColumn('string', 'X');
          dataTable.addColumn('number', 'Value');

          var oneDay = (1000 * 60 * 60 * 24);
          var startDate = new Date(2018, 9, 1);
          var endDate = new Date(2018, 9, 31);
          var ticksAxisH = ;
          for (var i = startDate.getTime(); i <= endDate.getTime(); i = i + oneDay) {
          var rowDate = new Date(i);
          var xValue = formatDate.formatValue(rowDate);
          var yValue = (2 * ((i - startDate.getTime()) / oneDay) + 8);
          dataTable.addRow([
          xValue,
          yValue
          ]);
          }

          var container = document.getElementById('chart_div');
          var chart = new google.visualization.LineChart(container);

          var options = {
          width: '100%',
          height: '100%',
          legend: {
          position: 'top',
          maxLines: 1,
          alignment: 'end'
          },
          chartArea: {
          bottom: 40,
          left: '8%',
          right: '8%',
          top: '10%',
          width: '100%',
          height: '75%'
          },
          backgroundColor: 'transparent',
          tooltip: {
          textStyle: {
          color: 'black'
          },
          isHtml: true
          },
          curveType: 'none',
          hAxis: {
          slantedText: true
          }
          };

          function drawChart() {
          chart.draw(dataTable, options);
          }

          drawChart();
          window.addEventListener('resize', drawChart, false);
          });

          <script src="https://www.gstatic.com/charts/loader.js"></script>
          <div id="chart_div"></div>








          share|improve this answer





















          • Thank you so much, this worked perfectly. Don't know how I missed this out in the documentation.
            – Hitesh
            Nov 21 at 11:42













          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          see the configuration options for hAxis



          for a slope representation, use --> slantedText: true




          hAxis.slantedText - If true, draw the horizontal axis text at an angle, to help fit more text along the axis.




          to enforce one level of labels, use --> maxAlternation: 1




          hAxis.maxAlternation - Maximum number of levels of horizontal axis text. If axis text labels become too crowded, the server might shift neighboring labels up or down in order to fit labels closer together.




          to keep the labels from wrapping on two lines, use --> maxTextLines: 1




          maxTextLines - Maximum number of lines allowed for the text labels. Labels can span multiple lines if they are too long, and the number of lines is, by default, limited by the height of the available space.




          note: you may need to adjust chartArea.bottom to allow more room along the x-axis...



          see following working snippet...






          google.charts.load('current', {
          packages:['corechart']
          }).then(function () {
          var dateFormat = 'dd MMM';
          var formatDate = new google.visualization.DateFormat({
          pattern: dateFormat
          });

          var dataTable = new google.visualization.DataTable();
          dataTable.addColumn('string', 'X');
          dataTable.addColumn('number', 'Value');

          var oneDay = (1000 * 60 * 60 * 24);
          var startDate = new Date(2018, 9, 1);
          var endDate = new Date(2018, 9, 31);
          var ticksAxisH = ;
          for (var i = startDate.getTime(); i <= endDate.getTime(); i = i + oneDay) {
          var rowDate = new Date(i);
          var xValue = formatDate.formatValue(rowDate);
          var yValue = (2 * ((i - startDate.getTime()) / oneDay) + 8);
          dataTable.addRow([
          xValue,
          yValue
          ]);
          }

          var container = document.getElementById('chart_div');
          var chart = new google.visualization.LineChart(container);

          var options = {
          width: '100%',
          height: '100%',
          legend: {
          position: 'top',
          maxLines: 1,
          alignment: 'end'
          },
          chartArea: {
          bottom: 40,
          left: '8%',
          right: '8%',
          top: '10%',
          width: '100%',
          height: '75%'
          },
          backgroundColor: 'transparent',
          tooltip: {
          textStyle: {
          color: 'black'
          },
          isHtml: true
          },
          curveType: 'none',
          hAxis: {
          slantedText: true
          }
          };

          function drawChart() {
          chart.draw(dataTable, options);
          }

          drawChart();
          window.addEventListener('resize', drawChart, false);
          });

          <script src="https://www.gstatic.com/charts/loader.js"></script>
          <div id="chart_div"></div>








          share|improve this answer












          see the configuration options for hAxis



          for a slope representation, use --> slantedText: true




          hAxis.slantedText - If true, draw the horizontal axis text at an angle, to help fit more text along the axis.




          to enforce one level of labels, use --> maxAlternation: 1




          hAxis.maxAlternation - Maximum number of levels of horizontal axis text. If axis text labels become too crowded, the server might shift neighboring labels up or down in order to fit labels closer together.




          to keep the labels from wrapping on two lines, use --> maxTextLines: 1




          maxTextLines - Maximum number of lines allowed for the text labels. Labels can span multiple lines if they are too long, and the number of lines is, by default, limited by the height of the available space.




          note: you may need to adjust chartArea.bottom to allow more room along the x-axis...



          see following working snippet...






          google.charts.load('current', {
          packages:['corechart']
          }).then(function () {
          var dateFormat = 'dd MMM';
          var formatDate = new google.visualization.DateFormat({
          pattern: dateFormat
          });

          var dataTable = new google.visualization.DataTable();
          dataTable.addColumn('string', 'X');
          dataTable.addColumn('number', 'Value');

          var oneDay = (1000 * 60 * 60 * 24);
          var startDate = new Date(2018, 9, 1);
          var endDate = new Date(2018, 9, 31);
          var ticksAxisH = ;
          for (var i = startDate.getTime(); i <= endDate.getTime(); i = i + oneDay) {
          var rowDate = new Date(i);
          var xValue = formatDate.formatValue(rowDate);
          var yValue = (2 * ((i - startDate.getTime()) / oneDay) + 8);
          dataTable.addRow([
          xValue,
          yValue
          ]);
          }

          var container = document.getElementById('chart_div');
          var chart = new google.visualization.LineChart(container);

          var options = {
          width: '100%',
          height: '100%',
          legend: {
          position: 'top',
          maxLines: 1,
          alignment: 'end'
          },
          chartArea: {
          bottom: 40,
          left: '8%',
          right: '8%',
          top: '10%',
          width: '100%',
          height: '75%'
          },
          backgroundColor: 'transparent',
          tooltip: {
          textStyle: {
          color: 'black'
          },
          isHtml: true
          },
          curveType: 'none',
          hAxis: {
          slantedText: true
          }
          };

          function drawChart() {
          chart.draw(dataTable, options);
          }

          drawChart();
          window.addEventListener('resize', drawChart, false);
          });

          <script src="https://www.gstatic.com/charts/loader.js"></script>
          <div id="chart_div"></div>








          google.charts.load('current', {
          packages:['corechart']
          }).then(function () {
          var dateFormat = 'dd MMM';
          var formatDate = new google.visualization.DateFormat({
          pattern: dateFormat
          });

          var dataTable = new google.visualization.DataTable();
          dataTable.addColumn('string', 'X');
          dataTable.addColumn('number', 'Value');

          var oneDay = (1000 * 60 * 60 * 24);
          var startDate = new Date(2018, 9, 1);
          var endDate = new Date(2018, 9, 31);
          var ticksAxisH = ;
          for (var i = startDate.getTime(); i <= endDate.getTime(); i = i + oneDay) {
          var rowDate = new Date(i);
          var xValue = formatDate.formatValue(rowDate);
          var yValue = (2 * ((i - startDate.getTime()) / oneDay) + 8);
          dataTable.addRow([
          xValue,
          yValue
          ]);
          }

          var container = document.getElementById('chart_div');
          var chart = new google.visualization.LineChart(container);

          var options = {
          width: '100%',
          height: '100%',
          legend: {
          position: 'top',
          maxLines: 1,
          alignment: 'end'
          },
          chartArea: {
          bottom: 40,
          left: '8%',
          right: '8%',
          top: '10%',
          width: '100%',
          height: '75%'
          },
          backgroundColor: 'transparent',
          tooltip: {
          textStyle: {
          color: 'black'
          },
          isHtml: true
          },
          curveType: 'none',
          hAxis: {
          slantedText: true
          }
          };

          function drawChart() {
          chart.draw(dataTable, options);
          }

          drawChart();
          window.addEventListener('resize', drawChart, false);
          });

          <script src="https://www.gstatic.com/charts/loader.js"></script>
          <div id="chart_div"></div>





          google.charts.load('current', {
          packages:['corechart']
          }).then(function () {
          var dateFormat = 'dd MMM';
          var formatDate = new google.visualization.DateFormat({
          pattern: dateFormat
          });

          var dataTable = new google.visualization.DataTable();
          dataTable.addColumn('string', 'X');
          dataTable.addColumn('number', 'Value');

          var oneDay = (1000 * 60 * 60 * 24);
          var startDate = new Date(2018, 9, 1);
          var endDate = new Date(2018, 9, 31);
          var ticksAxisH = ;
          for (var i = startDate.getTime(); i <= endDate.getTime(); i = i + oneDay) {
          var rowDate = new Date(i);
          var xValue = formatDate.formatValue(rowDate);
          var yValue = (2 * ((i - startDate.getTime()) / oneDay) + 8);
          dataTable.addRow([
          xValue,
          yValue
          ]);
          }

          var container = document.getElementById('chart_div');
          var chart = new google.visualization.LineChart(container);

          var options = {
          width: '100%',
          height: '100%',
          legend: {
          position: 'top',
          maxLines: 1,
          alignment: 'end'
          },
          chartArea: {
          bottom: 40,
          left: '8%',
          right: '8%',
          top: '10%',
          width: '100%',
          height: '75%'
          },
          backgroundColor: 'transparent',
          tooltip: {
          textStyle: {
          color: 'black'
          },
          isHtml: true
          },
          curveType: 'none',
          hAxis: {
          slantedText: true
          }
          };

          function drawChart() {
          chart.draw(dataTable, options);
          }

          drawChart();
          window.addEventListener('resize', drawChart, false);
          });

          <script src="https://www.gstatic.com/charts/loader.js"></script>
          <div id="chart_div"></div>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 at 12:51









          WhiteHat

          35.5k61375




          35.5k61375












          • Thank you so much, this worked perfectly. Don't know how I missed this out in the documentation.
            – Hitesh
            Nov 21 at 11:42


















          • Thank you so much, this worked perfectly. Don't know how I missed this out in the documentation.
            – Hitesh
            Nov 21 at 11:42
















          Thank you so much, this worked perfectly. Don't know how I missed this out in the documentation.
          – Hitesh
          Nov 21 at 11:42




          Thank you so much, this worked perfectly. Don't know how I missed this out in the documentation.
          – Hitesh
          Nov 21 at 11:42


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390836%2fgoogle-charts-x-axis-showing-up-down-values%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          Refactoring coordinates for Minecraft Pi buildings written in Python