min*_*int 12 javascript highcharts
我正在使用Highcharts并且想知道是否有可能在条形图中获得前3个结果,以便在图表的其余部分使用不同的颜色条?我正在从CSV文件填充图表.
这是我的javascript:
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
defaultSeriesType: 'bar'
},
title: {
text: 'Spiritual Gifts Results'
},
colors: [
'#3BBEE3'
],
xAxis: {
categories: []
},
yAxis: {
title: {
text: 'Service'
}
},
series: []
};
var data = document.getElementById("<%= hdn_Data.ClientID %>");
// Split the lines
if (data.value != "") {
var lines = data.value.split('\n');
// Iterate over the lines and add categories or series
$.each(lines, function(lineNo, line) {
var items = line.split(',');
// header line containes categories
if (lineNo == 0) {
$.each(items, function(itemNo, item) {
if (itemNo > 0) options.xAxis.categories.push(item);
});
}
// the rest of the lines contain data with their name in the first position
else {
var series = {
data: []
};
$.each(items, function(itemNo, item) {
if (itemNo == 0) {
series.name = item;
} else {
series.data.push(parseFloat(item));
}
});
options.series.push(series);
}
});
// Create the chart
var chart1 = new Highcharts.Chart(options);
}
});
Run Code Online (Sandbox Code Playgroud)
以下是CSV示例:
Categories,Administration,Evangelism,Mercy,Shepherding,Leadership,Wisdom,Teaching
Total Points,11,5,4,4,3,2,1
Run Code Online (Sandbox Code Playgroud)
所以在这个例子中,我喜欢'管理','布道'和'怜悯'有'蓝色条形',而'牧羊','领导'等有'红色条形'.
这可能吗?
这是小提琴
小智 14
这是一个例子
data: [
{ y: 34.4, color: 'red'}, // this point is red
21.8, // default blue
{y: 20.1, color: '#aaff99'}, // this will be greenish
20 // default blue
]
Run Code Online (Sandbox Code Playgroud)
Jas*_*ant 11
基于OP的评论,打破了我以前的答案.
就像你在做的那样
series.name = item;
Run Code Online (Sandbox Code Playgroud)
和
series.data.push(parseFloat(item));
Run Code Online (Sandbox Code Playgroud)
同样聪明,你可以这样做,
series.color: '#f6f6f6'
Run Code Online (Sandbox Code Playgroud)
(在你的循环中你可以根据你的条件改变颜色)
你可以做,
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
defaultSeriesType: 'bar'
},
title: {
text: 'Spiritual Gifts Results'
},
colors: [
'#3BBEE3'
],
xAxis: {
categories: []
},
yAxis: {
title: {
text: 'Service'
}
},
series: []
};
var data = document.getElementById("hdn_Data");
// Split the lines
if (data.value != "") {
var lines = data.value.split('\n');
// Iterate over the lines and add categories or series
$.each(lines, function(lineNo, line) {
var items = line.split(',');
// header line containes categories
if (lineNo == 0) {
$.each(items, function(itemNo, item) {
if (itemNo > 0) options.xAxis.categories.push(item);
});
}
// the rest of the lines contain data with their name in the first position
else {
var series = {
data: []
};
$.each(items, function(itemNo, item) {
var data = {};
if (itemNo == 0) {
series.name = item;
} else {
data.y = parseFloat(item);
if (itemNo <= 3) {
data.color = 'Gray';
}
else {
data.color = '#3BBEE3';
}
series.data.push(data);
}
});
options.series.push(series);
}
});
// Create the chart
var chart1 = new Highcharts.Chart(options);
}
});
Run Code Online (Sandbox Code Playgroud)
参考这个,你可以data用3种方式给出.我用过第三个.
| 归档时间: |
|
| 查看次数: |
31644 次 |
| 最近记录: |