抱歉,这里是对这个问题的更好描述。首先,我使用的是 asp.net/vb.net,并且我试图让一个图表与每个类别有 2 个系列的 Highcharts 一起使用。我正在检查列的值,我想根据那里的值设置列的颜色。
ASPX
<script type="text/javascript">
$(document).ready(function () {
$(function () {
$('#summary_chart').highcharts({
chart: {
type: 'column'
},
title: {
text: ' ',
align: 'left'
},
xAxis: {
categories: [<%= UserString %>]
},
yAxis: {
min: 0,
max: 9,
title: {
text: 'Grade'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' + '<td style="padding:0"><b>{point.y}</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
colors: [<%= ColorString %>],
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0,
colorByPoint: true
}
},
series: [{
name: 'Grade1',
data: [<%= Grade1String %>]
}, {
name: 'Grade2',
data: [<%= Grade2String %>]
}]
});
});
});
代码背后
' Building User String
For Each oRow In oTable
UserString += "'" & oRow.UserID & "',"
Next
' Building Grade1 Values
For Each oRow In oTable
If oRow.SkillDisplay = "Grade1" Then
Grade1String += "" & oRow.Grade & ","
' Determine colors to assign values
Select Case oRow.Grade
Case 1
ColorString += "'#FFC0CB',"
Case 2
ColorString += "'#000',"
Case 3
ColorString += "'#000',"
Case 4
ColorString += "'#FFA500',"
Case 5
ColorString += "'#FFA500',"
Case 6
ColorString += "'#008000',"
Case 7
ColorString += "'#659CEF',"
Case 8
ColorString += "'#0000FF',"
Case 9
ColorString += "'#0000FF',"
Case Else
ColorString += "'#fff',"
End Select
ElseIf oRow.SkillDisplay = "Grade2" Then
Grade2String += "" & oRow.Grade & ","
' Determine colors to assign values
Select Case oRow.Grade
Case 1
ColorString += "'#FFC0CB',"
Case 2
ColorString += "'#000',"
Case 3
ColorString += "'#000',"
Case 4
ColorString += "'#FFA500',"
Case 5
ColorString += "'#FFA500',"
Case 6
ColorString += "'#008000',"
Case 7
ColorString += "'#659CEF',"
Case 8
ColorString += "'#0000FF',"
Case 9
ColorString += "'#0000FF',"
Case Else
ColorString += "'#fff',"
End Select
End If
Next
'Remove last comma in string
UserString = UserString.Remove(UserString.Length - 1)
Grade1String = Grade1String.Remove(Grade1String.Length - 1)
Grade2tring = Grade2String.Remove(Grade2String.Length - 1)
ColorString = ColorString.Remove(ColorString.Length - 1)