Changing the X-axis view on a graph

Asked

Viewed 956 times

-1

I’m using the Google API to create some financial charts. Currently I have data in which the axis X (horizontal) represents the date and the axis Y (vertical) represents the quotation of the day:

Gráfico atualmente

The intervals shown in the following image indicate weekends (Saturday and Sunday), where there are no quotations:

Gráficos com intervalos dos finais de semana destacados

Is there any way, by the Google Graphics API, to remove these days from the view so that the chart looks like this?

Gráfico sem finais de semana

Here’s the code to start: http://jsfiddle.net/oam401z0/

I could change the first column to linear generated numerical data instead of dates, remove the caption and generate it on its own... but instead wanted to know if there is a more appropriate or practical way.

Note: I don’t need a solution that works specifically with weekends, there are holidays too, so an idea that would check null values would be better.

1 answer

0

You can put null in the data.

google.charts.load('current', {
  'packages': ['corechart']
});
google.charts.setOnLoadCallback(drawChart);

function drawChart() {

  var data = google.visualization.arrayToDataTable([
    ['Data', 'PLLO1 - Pallose'],
    [new Date('01/01/2015'), 1.00],
    [new Date('01/02/2015'), 1.02],
    [new Date('01/05/2015'), 1.04],
    [new Date('01/06/2015'), 1.06],
    [new Date('01/07/2015'), null],
    [new Date('01/08/2015'), 1.10],
    [new Date('01/09/2015'), 1.12],
    [new Date('01/12/2015'), 1.14],
    [new Date('01/13/2015'), 1.16],
    [new Date('01/14/2015'), 1.18]
  ]);

  var options = {
    title: 'Cotações da Empresa Pallose LTDA (fictícia)',
    pointSize: 5,
    legend: {
      position: 'bottom'
    }
  };

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

  chart.draw(data, options);
}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

<div id="curve_chart" style="width: 900px; height: 500px"></div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.