[英]Change Highcharts Series color
EDIT: So now I have a chart with all my data pushed off to the right, BUT I have labels in different colors for the sets I want to show but no data?? 编辑:所以现在我有一个图表,我的所有数据被推到右边,但我有不同颜色的标签,我想要显示的集,但没有数据? Updated my code
更新了我的代码
Original post: I have a working highchart here http://opensourcesurf.com/chart.html . 原帖:我在这里有一个工作高图http://opensourcesurf.com/chart.html 。 The problem is when I try and change the color of an individual data set, they all change.
问题是,当我尝试更改单个数据集的颜色时,它们都会发生变化。 How could I change these settings given my code?
如何根据我的代码更改这些设置? Thanks in advance!
提前致谢!
code: 码:
var options1 = {
chart: {
renderTo: 'container1',
type: 'area'
},
xAxis: {
type: 'datetime'
},
series: [{
name: 'Swell Period',
color: '#0066FF',
data: 'newSeriesData',
},
{ name: ' Maximum Breaking Wave Height',
color: '#ffffff',
data: 'newSeriesData',
},
{ name: 'Swell Height',
color: '#123456',
data: 'newSeriesData',
}],
};
var drawChart = function(data, name, color) {
var newSeriesData = {
name: name,
data: data
};
// Add the new data to the series array
options1.series.push(newSeriesData);
// If you want to remove old series data, you can do that here too
// Render the chart
var chart = new Highcharts.Chart(options1);
};
$.getJSON('decode.php', function(data){
drawChart(data, 'Swell Height');
});
$.getJSON('decode2.php', function(data){
drawChart(data, ' Maximum Breaking Wave Height');
});
$.getJSON('decode3.php', function(data){
drawChart(data, 'Swell Period');
});
Try this: 尝试这个:
// 'series' is an array of objects with keys:
// - 'name' (string)
// - 'data' (array)
// - 'color' (HTML color code)
var newSeriesData = {
name: name,
data: data,
color: color
};
The way to specify a color for a specific series is to define it when you're defining the series. 为特定系列指定颜色的方法是在定义系列时定义它。 For example:
例如:
series: [{
name: 'John',
color: '#0066FF',
dashStyle: 'ShortDash',
data: [
[Date.UTC(2010, 0, 1), 29.9],
[Date.UTC(2010, 2, 1), 71.5],
[Date.UTC(2010, 3, 1), 106.4]
]
},
So essentially when you're creating your series in your drawchart function, do a check for the name, and appropriately assign a color: 因此,当您在绘图功能中创建系列时,请检查名称,并适当地指定颜色:
var color;
if(name=="Swell Height"){
color="#0066FF";
}else if(name=="Maximum Breaking Wave Height"){
color="#0066EE";
}else if(name=="Swell Period"){
color="#0066HH";
}
var newSeriesData = {
name: name,
data: data,
color: color
};
在我看来,你不是在循环数据数组和/或你只有一组数据在data
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.