나는 레일을 사용하여,이 씨앗 데이터가있어 내보기 파일에서이 문자열을 제대로 분할 할 수 있습니까?
majors = 'business/marketing: 15%|social sciences: 14%|health professions: 11%|english: 10%|engineering: 9%|psychology: 8%|biology: 7%|history: 5%'
를, 내가 @college.majors
에 액세스하고 나는 |
에 분할하고, 그것을 밖으로 인쇄 할 수 있습니다. 그러나, 지금은 Google Charts을 사용하여 막대 그래프로 만들려고합니다. 그것은 다음과 같은 포맷해야 :
var popular_majors = google.visualization.arrayToDataTable([
['Major', 'Percentage'],
['Psychology', 20],
['Business', 15],
['Engineering', 12],
['Biology', 11],
['Economics', 8],
['History', 6],
['Mathematics', 5]
]);
(가) 짝수 제대로 문자열을 분할하고 내가 메이저 리그로 홀수 멤버를 인쇄 할 수있는 방법으로 그것을 반복하고하는 것이 가능 회원은 비율로?
코드 :
var popular_majors = google.visualization.arrayToDataTable(<%= @college.majors.gsub('%', '').split('|').map{ |element| element.split(': ') }.unshift(['Major', 'Percentage']).to_s.html_safe %>)
var popular_majors_options = {
title: 'Most Popular Majors',
legend: 'none',
hAxis: {title: 'Percentage'}
};
var chart = new google.visualization.BarChart(document.getElementById('popular_majors_chart'));
chart.draw(popular_majors, popular_majors_options);
var ethnicities = google.visualization.arrayToDataTable(<%= @college.ethnicity.gsub('%', '').split('|').map{ |element| element.split(': ') }.unshift(['Ethnicity', 'Percentage']).to_s.html_safe %>)
var ethnicities_options = {
title: 'Ethnicities',
legend: 'none',
hAxis: {title: 'Percentage'}
};
var chart = new google.visualization.BarChart(document.getElementById('ethnicities_chart'));
chart.draw(ethnicities, ethnicities_options);
예, 가능합니다. – Mischa