2014-02-24 2 views
2

꺾은 선형 차트를 그릴 경우 아무런 문제가 없지만 히스토그램 그래프에서이를 원합니다. (https://developers.google.com/chart/interactive/docs/gallery/histogram)Google 차트에서 세로선과 막대 그래프를 그리는 방법은 무엇입니까?

LineChart의 경우 :

var chart = new google.visualization.LineChart(document.querySelector('#chart_div')); 

히스토그램의 경우;

var chart = new google.visualization.Histogram(document.querySelector('#chart_div')); 

기타 코드;

function drawChart() { 
    var data = new google.visualization.DataTable(); 
    data.addColumn('string', 'Name'); 
    data.addColumn({type: 'string', role: 'annotation'}); 
    data.addColumn('number', 'Value'); 

    data.addRows([ 
     ['Foo', null, 4], 
     ['Bar', null, 3], 
     ['Baz', null, 7], 
     ['Bat', null, 9], 
     ['Cad', 'Vertical line here', 9], 
     ['Qud', null, 2], 
     ['Piz', null, 6] 
    ]); 

    var chart = new google.visualization.Histogram(document.querySelector('#chart_div')); 
    chart.draw(data, { 
     height: 300, 
     width: 400, 
     annotation: { 
      // index here is the index of the DataTable column providing the annotation 
      1: { 
       style: 'line' 
      } 
     } 
    }); 
} 

답변

3

다니엘 라리 베르테는 .. 그래서 구글 차트에 수 없습니다 구글의 수석 소프트웨어 엔지니어로 Google 그룹스, 내 질문 ..

https://groups.google.com/forum/#!msg/google-visualization-api/7y3LrKETEwY/fR4HoYwBu-EJ

대답

그러나 :) Google Charts는 SVG를 사용합니다 .. exp. 나는 미래의 방문객 .. (30) X 축에

var newLine = document.createElementNS('http://www.w3.org/2000/svg', 'line'); 
newLine.setAttribute('id', 'lineId'); 
newLine.setAttribute('style', 'stroke:rgb(0,0,0); stroke-width:3;');   
newLine.setAttribute('x1', chart.getChartLayoutInterface().getXLocation(30)); 
newLine.setAttribute('y1', chart.getChartLayoutInterface().getChartAreaBoundingBox().top); 
newLine.setAttribute('x2', chart.getChartLayoutInterface().getXLocation(30)); 
newLine.setAttribute('y2', chart.getChartLayoutInterface().getChartAreaBoundingBox().height + chart.getChartLayoutInterface().getChartAreaBoundingBox().top); 
$("svg").append(newLine); 
+1

을 선을 그어야 할이 또한 선 그래프에 "주석"라인에 애니메이션을 사용할 수 있습니다 - 나는 구글 그래프를 얻을 수있는 방법을 찾을 수 없습니다 주석의 변화하는 위치를 애니메이션으로 만들지 만, 위의 코드에 그려진 선의 X 위치에 애니메이션을 적용하는 것은 매우 간단합니다. 올바른 방향으로 밀어 주셔서 감사합니다, dustqm! – roguenet

관련 문제