javascript - 如何更改 Highchart 工具提示字体系列

标签 javascript html css highcharts

我想改变highchart的字体。我怎样才能改变这些?更改了 x 轴和 y 轴标签,但我无法更改工具提示字体

Highcharts.chart('container', {

    chart: {
        scrollablePlotArea: {
            minWidth: 700
        },
        style: {
            fontFamily: 'Bonbon'
       
        }
    },

    data: {
        csvURL: 'https://cdn.jsdelivr.net/gh/highcharts/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="335b5a545b505b524147407345041d031d03" rel="noreferrer noopener nofollow">[email protected]</a>/samples/data/analytics.csv',
        beforeParse: function (csv) {
            return csv.replace(/\n\n/g, '\n');
        }
    },

    title: {
        text: 'Daily sessions at www.highcharts.com'
    },

    subtitle: {
        text: 'Source: Google Analytics'
    },

    xAxis: {
        tickInterval: 7 * 24 * 3600 * 1000, // one week
        tickWidth: 0,
        gridLineWidth: 1,
        labels: {
            align: 'left',
            x: 3,
            y: -3
        }
    },

    yAxis: [{ // left y axis
        title: {
            text: null
        },
         tooltip: {
        
        backgroundColor: null,
        borderWidth: 0,
        shadow: false,
        useHTML: false,
        style: {
            padding: 0
        }
    },
        labels: {
            align: 'left',
            x: 3,
            y: 16,
            format: '{value:.,0f}'
        },
        showFirstLabel: false
    }, { // right y axis
        linkedTo: 0,
        gridLineWidth: 0,
        opposite: true,
        title: {
            text: null
        },
        labels: {
            align: 'right',
            x: -3,
            y: 16,
            format: '{value:.,0f}'
        },
        showFirstLabel: false
    }],

    legend: {
        align: 'left',
        verticalAlign: 'top',
        borderWidth: 0
    },

    tooltip: {
        shared: true,
        crosshairs: true
    },

    plotOptions: {
        series: {
            cursor: 'pointer',
            point: {
                events: {
                    click: function (e) {
                        hs.htmlExpand(null, {
                            pageOrigin: {
                                x: e.pageX || e.clientX,
                                y: e.pageY || e.clientY
                            },
                            headingText: this.series.name,
                            maincontentText: Highcharts.dateFormat('%A, %b %e, %Y', this.x) + ':<br/> ' +
                                this.y + ' sessions',
                            width: 200
                        });
                    }
                }
            },
            marker: {
                lineWidth: 1
            }
        }
    },

    series: [{
        name: 'All sessions',
        lineWidth: 4,
        marker: {
            radius: 4
        }
    }, {
        name: 'New users'
    }]
});
.highcharts-tooltip>span {
font-family:Bonbon!important;

}
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<!-- Additional files for the Highslide popup effect -->

<link href="https://fonts.googleapis.com/css?family=Roboto+Slab&display=swap" rel="stylesheet"> 
<script src="https://www.highcharts.com/media/com_demo/js/highslide-full.min.js"></script>
<script src="https://www.highcharts.com/media/com_demo/js/highslide.config.js" charset="utf-8"></script>
<link href="https://fonts.googleapis.com/css?family=Bonbon&display=swap" rel="stylesheet"/>
<link rel="stylesheet" type="text/css" href="https://www.highcharts.com/media/com_demo/css/highslide.css" />


<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

最佳答案

在您的工具提示中添加样式{},它将是工作或refer this documentation

style: {
   fontFamily:'Bonbon'
}

Highcharts.chart('container', {

    chart: {
        scrollablePlotArea: {
            minWidth: 700
        },
        style: {
            fontFamily: 'Bonbon'
       
        }
    },

    data: {
        csvURL: 'https://cdn.jsdelivr.net/gh/highcharts/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2f474648474c474e5d5b5c6f5918011f011f" rel="noreferrer noopener nofollow">[email protected]</a>/samples/data/analytics.csv',
        beforeParse: function (csv) {
            return csv.replace(/\n\n/g, '\n');
        }
    },

    title: {
        text: 'Daily sessions at www.highcharts.com'
    },

    subtitle: {
        text: 'Source: Google Analytics'
    },

    xAxis: {
        tickInterval: 7 * 24 * 3600 * 1000, // one week
        tickWidth: 0,
        gridLineWidth: 1,
        labels: {
            align: 'left',
            x: 3,
            y: -3
        }
    },

    yAxis: [{ // left y axis
        title: {
            text: null
        },
         tooltip: {
        
        backgroundColor: null,
        borderWidth: 0,
        shadow: false,
        useHTML: false,
        style: {
            padding: 0
        }
    },
        labels: {
            align: 'left',
            x: 3,
            y: 16,
            format: '{value:.,0f}'
        },
        showFirstLabel: false
    }, { // right y axis
        linkedTo: 0,
        gridLineWidth: 0,
        opposite: true,
        title: {
            text: null
        },
        labels: {
            align: 'right',
            x: -3,
            y: 16,
            format: '{value:.,0f}'
        },
        showFirstLabel: false
    }],

    legend: {
        align: 'left',
        verticalAlign: 'top',
        borderWidth: 0
    },

    tooltip: {
        shared: true,
        crosshairs: true,
        style: {
            //fontWeight: 'bold',
            fontFamily:'Bonbon'
        }
    },
    

    plotOptions: {
        series: {
            cursor: 'pointer',
            point: {
                events: {
                    click: function (e) {
                        hs.htmlExpand(null, {
                            pageOrigin: {
                                x: e.pageX || e.clientX,
                                y: e.pageY || e.clientY
                            },
                            headingText: this.series.name,
                            maincontentText: Highcharts.dateFormat('%A, %b %e, %Y', this.x) + ':<br/> ' +
                                this.y + ' sessions',
                            width: 200
                        });
                    }
                }
            },
            marker: {
                lineWidth: 1
            }
        }
    },

    series: [{
        name: 'All sessions',
        lineWidth: 4,
        marker: {
            radius: 4
        }
    }, {
        name: 'New users'
    }]
});
/*-- or you try with css --*/

/*.highcharts-tooltip > text > tspan {
  font-family: Bonbon !important;
}*/
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<!-- Additional files for the Highslide popup effect -->

<link href="https://fonts.googleapis.com/css?family=Roboto+Slab&display=swap" rel="stylesheet"> 
<script src="https://www.highcharts.com/media/com_demo/js/highslide-full.min.js"></script>
<script src="https://www.highcharts.com/media/com_demo/js/highslide.config.js" charset="utf-8"></script>
<link href="https://fonts.googleapis.com/css?family=Bonbon&display=swap" rel="stylesheet"/>
<link rel="stylesheet" type="text/css" href="https://www.highcharts.com/media/com_demo/css/highslide.css" />


<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

关于javascript - 如何更改 Highchart 工具提示字体系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57178661/

相关文章:

javascript - 为什么我的 ID 容器在 Document.ready 匿名函数中没有从蓝色变为红色

javascript - 嵌入式 Youtube 视频自动播放 - 在图像幻灯片中间

javascript - 如何通过javascript获取ntp时间

javascript - 用于单个文本的 HTML5 Canvas RTL

html - 容器不随内容扩展

html - 在 Bootstrap Segmented 输入组右侧添加圆 Angular

javascript - 如何修复堆叠对数条形图值以适合网格

javascript - 有人可以帮我找到一个更好的替代方法来替代我编写的这个 Javascript for 循环吗?

jquery - 图像 slider 自动循环功能

jquery - CSS:滑动按钮onclick并显示内容?