我想讓標籤出現在我的柱形圖上。Highcharts,ROR,如何讓標籤工作
的JavaScript
<%= javascript_tag do %>
window.highchartDATA = '<%= @data %>';
<% end %>
dashboard.html.erb
<script>
$(function() {
$('#notes_chart').highcharts({
chart: {
type: 'column',
backgroundColor: {
linearGradient: { x1: 0, y1: 0, x2: 1, y2: 1 },
stops: [
[0, '#2a2a2b'],
[1, '#3e3e40']
]
},
},
title: {
text: 'Total Notes By Class Module'
},
subtitle: {
text: 'Source: Notes Table'
},
xAxis: {
categories: [],
title: {
text: null
},
labels: {
overflow: 'justify',
style: {
color: '#FFFFFF',
font: '11px Trebuchet MS, Verdana, sans-serif'
}
}
},
yAxis: {
min: 0,
title: {
text: 'Total Number',
align: 'high'
},
labels: {
overflow: 'justify',
style: {
color: '#FFFFFF',
font: '11px Trebuchet MS, Verdana, sans-serif'
}
}
},
tooltip: {
valueSuffix: ''
},
plotOptions: {
column: {
dataLabels: {
enabled: true
}
}
},
credits: {
enabled: false
},
series: [{
name: 'Number of Notes By Class Module',
data: <%= @data %>
}]
});
});
</script>
Note.rb
def self.getData
data = []
self.subject_types.each do |type|
data << self.type_count(type)
end
data
end
private
def self.subject_types
pluck(:subject_type).uniq
end
def self.type_count(type)
where(subject_type: type).count
end
end
控制器:notes_controller.rb
def dashboard
@data = Note.highchart_data
end
該圖是從下面的模型填充:
create_table "classmodules", force: :cascade do |t|
t.integer "student_id"
t.string "subject"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
目前這個工程。但是我無法讓標籤出現在柱形圖上。我如何讓標籤自動出現?所有這一切都有1,2,3,4等....謝謝!
你想數據標籤的出現或你指的是標籤上的x和y軸? –
謝謝。我指的是X軸上的標籤。我所得到的是0,1,2,3等。我可以讓他們自動更新模型/表格嗎? – Co2