Mac*_*acD 4 javascript highcharts
编辑:所以现在我有一个图表,我的所有数据被推到右边,但我有不同颜色的标签,我想要显示的集,但没有数据?更新了我的代码
原帖:我在这里有一个工作高图http://opensourcesurf.com/chart.html.问题是,当我尝试更改单个数据集的颜色时,它们都会发生变化.如何根据我的代码更改这些设置?提前致谢!
码:
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');
});
Run Code Online (Sandbox Code Playgroud)
Eth*_* Wu 10
试试这个:
// 'series' is an array of objects with keys:
// - 'name' (string)
// - 'data' (array)
// - 'color' (HTML color code)
var newSeriesData = {
name: name,
data: data,
color: color
};
Run Code Online (Sandbox Code Playgroud)
小智 5
为特定系列指定颜色的方法是在定义系列时定义它。例如:
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]
]
},
Run Code Online (Sandbox Code Playgroud)
所以基本上当你在你的绘图功能中创建你的系列时,检查名称,并适当地分配一种颜色:
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
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16293 次 |
| 最近记录: |