0

I made a jsfiddle example to demo this.
http://jsfiddle.net/daxu/ttxvpduv/.

    $(function () {
    $('#container').highcharts({

        legend: {
            enabled: true
        },

        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },

        series: [{
            name:'a',
            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
        },
                {
            name:'b',
                    type:'area',
            data: [129.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
        }]
    });
}); 

In my example, I have two series (one line, one area). We can see that the legend for line chart is a line, and the legend area is bigger (like an area).

Is there a way to make all legends a line or some style?

Many Thanks

DJ Burb
  • 2,346
  • 2
  • 29
  • 38
daxu
  • 3,514
  • 5
  • 38
  • 76
  • You need to use "fake" serie like in the topic http://stackoverflow.com/questions/27510810/highcharts-make-the-legend-symbol-a-square-or-rectangle/27535466#27535466 – Sebastian Bochan Dec 19 '14 at 10:39
  • Saw that example, but how can I make the fake series to show at bottom other than right? All our legends need to be at the bottom. – daxu Dec 19 '14 at 13:36

2 Answers2

1

This is a little hacky (maybe I've just been using d3.js too much lately) but you could modify the SVG on the fly:

, function(chart){
    // remove the line and rect
    $('.highcharts-legend-item path, .highcharts-legend-item rect').remove();
    // add in your own elements
    $('.highcharts-legend-item').each(function(i, obj){
        var circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
        $(circle).attr({"r":10,"fill":"red", "cy": 10});
        $(obj).append(circle);
    });
});

Fiddle here.

Mark
  • 106,305
  • 20
  • 172
  • 230
1

worked out this now.

see http://jsfiddle.net/ttxvpduv/2/

   Highcharts.seriesTypes.line.prototype.drawLegendSymbol = 
     Highcharts.seriesTypes.column.prototype.drawLegendSymbol;
daxu
  • 3,514
  • 5
  • 38
  • 76