Javascript 需要更改标题颜色甜甜圈highchart
这是我的函数,它在我的html中呈现圆环图。我能够为图例标记/图标添加动态颜色。但现在我需要把动态颜色的传奇标题以及。我能弄明白 我该怎么做?请帮忙Javascript 需要更改标题颜色甜甜圈highchart,javascript,highcharts,Javascript,Highcharts,这是我的函数,它在我的html中呈现圆环图。我能够为图例标记/图标添加动态颜色。但现在我需要把动态颜色的传奇标题以及。我能弄明白 我该怎么做?请帮忙 const chart = new Highcharts.Chart( { chart: { color: '#000', backgroundColor: '#336196', renderTo: 'container', type
const chart = new Highcharts.Chart(
{
chart: {
color: '#000',
backgroundColor: '#336196',
renderTo: 'container',
type: 'pie'
},
title: {
text: "What's using data",
style: {
color: '#000'
}
},
yAxis: {
title: {
text: 'Total percent market share'
}
},
plotOptions: {
pie: {
shadow: false,
borderColor: null
}
},
tooltip: {
formatter: function() {
return '<b>' + this.point.name + '</b>: ' + this.y + ' %'
}
},
legend: {
align: 'right',
layout: 'vertical',
verticalAlign: 'middle',
symbolRadius: 0,
symbolPadding: 10,
itemMarginTop: 15,
itemStyle: {
color: '#fff'
}
},
series: [
{
name: 'Browsers',
data: data,
size: '120%',
innerSize: '60%',
showInLegend: true,
dataLabels: {
enabled: false
},
marker: {
symbol: 'square',
radius: 12
}
}
]
},
function(chart) {
var textX = chart.plotLeft + chart.plotWidth * 0.5
var textY = chart.plotTop + chart.plotHeight * 0.52
var span =
'<div id="pieChartInfoText" style="position:absolute; text-align:center;">'
span +=
'<div style="color:#fff;font-size: 20px;width:50pxmargin-top:36px;margin-left:18px;"></div><br>'
span += '</div>'
$('#addText').append(span)
span = $('#pieChartInfoText')
span.css('left', textX + span.width() * -0.5)
span.css('top', textY + span.height() * -0.5)
}
)
const chart=new Highcharts.chart(
{
图表:{
颜色:“#000”,
背景颜色:“#336196”,
renderTo:'容器',
键入:“馅饼”
},
标题:{
文本:“什么在使用数据”,
风格:{
颜色:“#000”
}
},
亚克斯:{
标题:{
文字:“总市场份额百分比”
}
},
打印选项:{
馅饼:{
影子:错,
边框颜色:空
}
},
工具提示:{
格式化程序:函数(){
返回“+this.point.name+”:“+this.y+”%”
}
},
图例:{
对齐:“右”,
布局:“垂直”,
垂直排列:'中间',
符号半径:0,
符号:10,
项目编号:15,
项目样式:{
颜色:'#fff'
}
},
系列:[
{
名称:'浏览器',
数据:数据,
大小:“120%”,
内部尺寸:“60%”,
showInLegend:是的,
数据标签:{
已启用:false
},
标记:{
符号:'正方形',
半径:12
}
}
]
},
功能(图表){
var textX=chart.plotLeft+chart.plotWidth*0.5
var textY=chart.plotTop+chart.plotHeight*0.52
var跨度=
''
跨度+=
“
”
span+=''
$('#addText')。追加(span)
span=$(“#pieChartInfoText”)
css('left',textX+span.width()*-0.5)
css('top',textY+span.height()*-0.5)
}
)
任何帮助都将不胜感激。谢谢你 要更改图例颜色标题,只需设置:
legend: {
title: {
text: 'legend title',
style: {
color: 'red'
}
}
}
但是,如果要更改单个图例项文本,则需要使用:
function(chart) {
var legendItems = $(".highcharts-legend-item");
$(legendItems[0].children[0]).css('fill', 'red');
}
现场演示:
这将起到作用一个简单的谷歌搜索可以帮你做到这一点:可能重复@Megajin
title。样式
或你链接的重复目标在这里都不合适。就我所见,它们完全不相关。@Megajin这是一个折线图,我想问的是甜甜圈图。有区别。@ewolden有什么解决方案吗?设置颜色不是问题,他想动态设置颜色。即,图例文本与饼图每个部分的颜色相匹配。像这样:谢谢你的提示@ewolden。然而,我认为我的答案是正确的,使用上面的代码很容易达到所需的结果:@ewolden和ppotaczek答案有效,但颜色在hower上消失。请给我一些建议。黑骑士,请检查一下这个例子:请让我知道这是否符合你的要求。
title:{
text: 'Something',
style: {"color": "#003C71", "fontSize": "18px"}
}