0

抱歉,这里是对这个问题的更好描述。首先,我使用的是 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)
4

2 回答 2

1

事实证明,您可以将自己的数据数组作为对象,而不仅仅是数据的数字。以下是 highcharts 的“系列”部分的示例部分,每个数据点都有不同的颜色 [希望你可以使用这个]

series: [{
    name: 'Population',
    data: [{
        color: '#FF9999',
        y: 34.4
    },{
        color: '#339900',
        y: 21.8
    },{
        color: '#6600FF',
        y: 20.1
    }],
},
{
    name: 'Population',
    data: [{
        color: '#FF0033',
        y: 34.4
    },{
        color: '#99CC66',
        y: 21.8
    },{
        color: '#3366CC',
        y: 20.1
}]

您可能可以直接指定“x”值,但是当我尝试时,Highcharts 足够聪明,可以将每个值与类别列表进行匹配。

于 2013-07-23T20:45:57.667 回答
0

http://jsfiddle.net/5a7PS/请看这个 JSFiddle 并查看系列数据。我已经为每个系列分配了颜色属性,因此它改变了列颜色。

series: [{
            name: 'Tokyo',
            color: '#0000FF',
            data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]

        }, {
            name: 'New York',
            color:'#659CEF',
            data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3]

        }, {
            name: 'London',
            color:'#FFC0CB',
            data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2]

        }, {
            name: 'Berlin',
            color:'#FFA500',
            data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1]
}]

希望这是你想要的。

我还尝试修改您的代码。你可以在这里看到它http://jsfiddle.net/DwW3m/100/(我删除了 colorByPoint: true )并且它有效!

于 2013-07-23T19:18:15.373 回答