I am looking to use String as label for the X-Axis of Google Chart api for Line chart where I am joining two set of data to plot two lines in single line chart, I managed to make it work with no String label (works with number) but no haxis lines are shown
google.charts.load('current', {'packages': ['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data1 = new google.visualization.DataTable();
data1.addColumn('string', 'Month');
data1.addColumn('number', 'Average Sales Price');
data1.addColumn({type: 'string', role: 'tooltip', p: {'html': true}});
data1.addRows([
[{v: 0, f:'Q4 2013'}, 3,'<span class="total-home-tooltip">$300K Some html - 1!</span>'],
[{v: 1, f:'Q1 2014'}, 6,'<span class="total-home-tooltip">$600K Some html - 2!</span>'],
[{v: 2, f:'Q2 2014'}, 5,'<span class="total-home-tooltip">$500K Some html - 3!</span>'],
[{v: 3, f:'Q3 2014'}, 8,'<span class="total-home-tooltip">$800K Some html - 4!</span>'],
[{v: 4, f:'Q4 2014'}, 2,'<span class="total-home-tooltip">$200K Some html - 5!</span>'],
[{v: 5, f:'Q1 2015'}, 5,'<span class="total-home-tooltip">$500K Some html - 6!</span>'],
[{v: 6, f:'Q2 2015'}, 5,'<span class="total-home-tooltip">$500K Some html - 7!</span>']
]);
var data2 = new google.visualization.DataTable();
data2.addColumn('string', 'Month');
data2.addColumn('number', 'Median Sales Price');
data2.addColumn({type: 'string', role: 'tooltip', p: {'html': true}});
/*if we would like to show string in x asix we have to use data in format {v: 0, f:'Q4 2013'} otherwise google api will not draw haxis lines */
data2.addRows([
[{v: 0, f:'Q4 2013'}, 5,'<span class="total-home-tooltip">Some html here</span>'],
[{v: 1, f:'Q1 2014'}, 1,'<span class="total-home-tooltip">Some html here</span>'],
[{v: 2, f:'Q2 2014'}, 3,'<span class="total-home-tooltip">Some html here</span>'],
[{v: 3, f:'Q3 2014'}, 9,'<span class="total-home-tooltip">Some html here</span>'],
[{v: 4, f:'Q4 2014'}, 4,'<span class="total-home-tooltip">Some html here</span>'],
[{v: 5, f:'Q1 2015'}, 5,'<span class="total-home-tooltip">Some html here</span>'],
[{v: 6, f:'Q2 2015'}, 7,'<span class="total-home-tooltip">Some html here</span>']
]);
var options1 = {
legend: {
position: 'bottom',
textStyle: {color: 'black', fontSize: 14},
pointShape: "triangle",
alignment: 'end'
},
interpolateNulls: true,
height: 312,
width: 1070,
colors: ['#EBAD00','#00ACE0'],
pointSize: 8,
backgroundColor: {fill: "transparent"},
tooltip: {isHtml: true},
hAxis: {
minValue: 0,
baselineColor:"#BBBBBB"
},
vAxis: {
gridlines: {color: "transparent"},
minValue: 0,
baselineColor:"#BBBBBB"
},
ticks: [{v: 0, f:'Jan'},{v: 1, f:'Feb'},{v: 2, f:'Mar'},{v: 3, f:'Apr'},{v: 4, f:'May'},{v: 5, f:'June'},{v: 6, f:'July'}], // <------- This does the trick
annotations: {
style: 'line'
}
};
var joinedData = google.visualization.data.join(data1, data2, 'full', null, [1,2], [1,2]);
var chart = new google.visualization.LineChart(document.getElementById('market_trend_chart1'));
chart.draw(joinedData, options1 );
}
<div id="market_trend_chart1"></div>
I get this error Error: Type mismatch. Value 0 does not match type string in column index 0 , I understand the error is mismatch of variable type but not very sure how to resolve this
Working Fiddle with no string label http://jsfiddle.net/j29Pt/536/ (issue is now there are no haxis lines) If I try to add String as label http://jsfiddle.net/j29Pt/535/ the chart seems to stop working