css - Google bar chart data labels positioning -
how change google bar chart data labels position ? have data labels (2003,2004,...) between bars - not straight below them now.enter image description here
function drawvisualization() { // create , populate data table. var data = google.visualization.arraytodatatable([ ['year', 'austria', 'bulgaria', 'denmark', 'greece'], ['2003', 1336060, 400361, 1001582, 997974], ['2004', 1538156, 366849, 1119450, 941795], ['2005', 1576579, 440514, 993360, 930593], ['2006', 1600652, 434552, 1004163, 897127], ['2007', 1968113, 393032, 979198, 1080887], ['2008', 1901067, 517206, 916965, 1056036] ]); // create , draw visualization. new google.visualization.columnchart(document.getelementbyid('chart')). draw(data, {title:"yearly coffee consumption country", width:600, height:400, vaxis: {title: "year"}, isstacked: true, haxis: {title: "cups"}} ); } google.load("visualization", "1", {packages:["corechart"]}); google.setonloadcallback(drawvisualization);
here options...
i've added null
rows space data , moved labels null
rows.
this causes labels appear on second line.
thought maxalternation
might correct issue slants text.
chart_1 looks best me...
google.charts.load('current', {packages: ['corechart']}); google.charts.setonloadcallback(drawvisualization); function drawvisualization() { // add null data label placement var data = google.visualization.arraytodatatable([ ['year', 'austria', 'bulgaria', 'denmark', 'greece'], [null, 1336060, 400361, 1001582, 997974], ['2003', null, null, null, null], [null, 1538156, 366849, 1119450, 941795], ['2004', null, null, null, null], [null, 1576579, 440514, 993360, 930593], ['2005', null, null, null, null], [null, 1600652, 434552, 1004163, 897127], ['2006', null, null, null, null], [null, 1968113, 393032, 979198, 1080887], ['2007', null, null, null, null], [null, 1901067, 517206, 916965, 1056036], ['2008', null, null, null, null] ]); var options = { width: 600, height: 400, vaxis: { title: "year" }, isstacked: true, haxis: { title: "cups" } }; // labels appear on second line (of course) options.title = 'chart_0'; var chart1 = new google.visualization.columnchart( document.getelementbyid('chart0') ).draw(data, options); // maxalternation slants text options.title = 'chart_1'; options.haxis.maxalternation = 1; var chart1 = new google.visualization.columnchart( document.getelementbyid('chart1') ).draw(data, options); // can control slant 1-90 // setting 0 causes labels not display options.title = 'chart_2'; options.haxis.slantedtext = true; options.haxis.slantedtextangle = 90; var chart1 = new google.visualization.columnchart( document.getelementbyid('chart2') ).draw(data, options); drawvisualizationleft(); } function drawvisualizationleft() { // add null data label placement var data = google.visualization.arraytodatatable([ ['year', 'austria', 'bulgaria', 'denmark', 'greece'], ['2003', null, null, null, null], [null, 1336060, 400361, 1001582, 997974], ['2004', null, null, null, null], [null, 1538156, 366849, 1119450, 941795], ['2005', null, null, null, null], [null, 1576579, 440514, 993360, 930593], ['2006', null, null, null, null], [null, 1600652, 434552, 1004163, 897127], ['2007', null, null, null, null], [null, 1968113, 393032, 979198, 1080887], ['2008', null, null, null, null], [null, 1901067, 517206, 916965, 1056036] ]); var options = { width: 600, height: 400, vaxis: { title: "year" }, isstacked: true, haxis: { title: "cups" } }; // maxalternation slants text options.title = 'chart_3'; options.haxis.maxalternation = 1; var chart3 = new google.visualization.columnchart( document.getelementbyid('chart3') ).draw(data, options); }
<script src="https://www.gstatic.com/charts/loader.js"></script> <div id="chart0"></div> <div id="chart1"></div> <div id="chart2"></div> <div id="chart3"></div>
Comments
Post a Comment