【问题标题】:Highcharts Styling QuestionsHighcharts 样式问题
【发布时间】:2013-04-19 01:40:07
【问题描述】:

我希望对设置线条 Highchart 的样式有所帮助。

我正在尝试让此处的图表看起来像图像:

Example of my graph

但我很难获得块色标签?

任何帮助将不胜感激!

谢谢

$('#container').highcharts({
        chart: {
            type: 'line',
            plotBackgroundImage: 'images/fibre.jpg',
            plotBorderWidth: 0,


            /*,
            marginRight: 130,
            marginBottom: 25*/
        },
        title: 
        {
            text    : strTitle
        },
        tooltip: 
        {
            enabled: false
        },
        xAxis: 
        {
            categories: arrXAxis,               
            title: 
            {
                text: strXTitle
            },

        },          
        yAxis: 
        {
            title: 
            {
                text: ''
            },
            labels: {
                formatter: function() {
                   // return this.value +'?'
                   return('');
                }
            },
            min: 0,
            max: 10,
            minorGridLineWidth: 0,
            alternateGridColor: null,
            gridLineWidth: 0,
            plotBands: 
            [{ 
                from: intRedStart,
                to: intRedEnd,
                color: 'rgba(229, 28, 36, 0.6)',
                label: 
                {
                    text: 'High Risk',
                    style: 
                    {
                        color: '#606060'
                    }
                }
            },
            { 
                from: intAmberStart,
                to: intAmberEnd,
                color: 'rgba(239, 140, 30, 0.6)',
                label: 
                {
                    text: 'Improvement',
                    style: 
                    {
                        color: '#606060'
                    }
                }
            },
            { 
                from: intGreenStart,
                to: intGreenEnd,
                color: 'rgba(43, 174, 115, 0.6)',
                label: 
                {
                    text: 'Healthy',
                    style: 
                    {
                        color: '#606060'
                    }
                }
            }   


            ]
        },
        legend: {
           /*
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -10,
            y: 100,
            borderWidth: 0*/
        },
        series:
        [{
            allowPointSelect: false,    
            showInLegend: false,
            data: arrData   
        }   /*, {
                name: '1',
                data: [10]
            }, {
                name: '2',
                data: [0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
            }, {
                name: '3',
                data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
            }*/]
    });

【问题讨论】:

    标签: highcharts


    【解决方案1】:

    如果您查看API doc for plotband labels,我认为您应该能够通过使用“style”、“align”和“verticalAlign”属性来做与图像类似的事情。希望这会有所帮助:)

    编辑:似乎无法使用 labels.style 对象设置背景颜色。我猜这是因为标签是一个 SVG 元素(更具体地说是一个 tspan),所以它不支持标准 HTML 元素所做的所有 css。但是,您可以通过对齐标签“顶部”和“左侧”来更接近您的目标,并设置字体颜色。如果你真的需要背景颜色,你可以看看这个:Background color of tspan element

    【讨论】:

      【解决方案2】:

      您可以为图表http://api.highcharts.com/highcharts#chart.plotBackgroundImage 设置plotBackgroundImage,然后使用plotBands http://jsfiddle.net/JRhaS/2/

       plotBands: [{ // mark the weekend
                  color: 'rgba(155,255,155,0.5)',
                  from: 0,
                  to: 100
              },{ // mark the weekend
                  color: 'rgba(100,255,200,0.5)',
                  from:100,
                  to: 200
              }],
          },
      

      【讨论】:

      • 您好,感谢您的回复,但我正在尝试重新创建带有“健康”、“改进”、“高风险”字样的纯色块 - 而不是图像上的不透明图带!
      • 你有没有尝试设置 plotbands 标签? api.highcharts.com/highcharts#xAxis.plotBands.label ?
      • 标签有效,但设置背景颜色样式似乎不起作用。图表标签也是如此。我找不到做 TheBounder 想要的方法。我已经更新了他的帖子以包含来自他的链接的图表来源。
      • @SteveP backgroundcolor 标签或 plotband?我不确定?
      • 在标签样式中设置背景颜色似乎不起作用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多