可以强制Highcarts对折线图中的所有系列使用圆形符号

Possible to force Highcarts to use the circle symbol for all the series in a line graph?

本文关键字:系列 符号 Highcarts 折线图      更新时间:2023-09-26

我希望所有的线都使用相同的圆形符号。

这是我目前拥有的:

$TopChartJS = $(function () {
    var chart = new Highcharts.Chart({
        colors: ["#cc1c0d", "#1d63af" , "#9eb215"],
        chart: {
            type: 'line',
            backgroundColor:'rgba(255, 255, 255, 0.85)',
            renderTo: 'container'
        },
        data: {
            table: 'sheet6'
        },
        title: {
            text: 'Cost Comparison'
        },
        xAxis: {
            tickInterval:3,
            title: {
                text: 'Months'
            },
        },
        plotOptions: {
            series: {
                marker: {
                    radius: 3,
                    fillColor: '#FFFFFF',
                    lineWidth: 2,
                    lineColor: null // inherit from series
                },
                shadow: true
            }
        },
        yAxis: {
            allowDecimals: false,
            title: {
                text: 'Cost [kUSD]'
            },
            labels: {
                formatter: function () {
                    return Highcharts.numberFormat(this.value,0);
                }
            }
        },
        credits: {
            enabled: false
        },
        tooltip: {
            headerFormat: '<b>{series.name}</b><br>',
            pointFormat: 'Month {point.x}: {point.y} kUSD'
        },
    });
});

我的图表中有三个系列,我希望它们都使用相同的圆圈符号,但颜色不同。

我曾尝试将plottoptions标记符号定义添加到各个部分,但这似乎不起作用,图表也不再显示。

这可能吗?

是的,您可以将标记的绘图选项设置为圆形,它将用于所有系列。例如(JSFiddle):

$('#container').highcharts({
    plotOptions: {
        series: {
            marker: {
                symbol: 'circle'
            }
        }
    },
    series: [{
        data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
    }, {
        data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
    }, {
        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]
    }]
});