在我的数据库我已存储的颜色为一个字符串,我需要将这些颜色转换为十六进制和实施饼图上。有没有一个好的方法来做到这一点?
这是我的javascript代码。有两个数组(系列和颜色)存储数据。如何在饼图中实现数据库中的颜色?
<script type="text/javascript">
$(function() {
$.ajax({
url: 'getItems',
dataType: "json",
type: "GET",
contentType: 'application/json; charset=utf-8',
async: false,
processData: false,
cache: false,
delay: 15,
success: function (data) {
var series = new Array();
var colors = new Array();
for (var i in data) {
var serie = new Array(data[i].name, data[i].y, data[i].color);
series.push(serie);
colors.push(serie[data[i].color]);
}
DrawPieChart(series,colors);
},
error: function (xhr) {
alert('error');
}
});
});
function DrawPieChart(series,colors) {
console.log(series,colors);
Highcharts.chart('container', {
chart: {
plotBackgroundColor: null,
plotBorderWidth: 1,
plotShadow: false,
},
title: {
text: ' Vehicle Summary'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},
colors: [colors],
series: [{
type: 'pie',
name: 'Task Status',
data: series
}]
});
}
</script>
这是我的方法,它从数据库过程中的项目的值称为“百分比”。
public ActionResult getItems()
{
List<itemViewModel> result = new List<itemViewModel>();
result = unitOfWork.ExecuteSP<itemViewModel>("[percentage]");
var res = result.OfType<string>();
foreach (var dr in res)
{
itemViewModel summary = new itemViewModel();
summary.name = dr[0].ToString().Trim();
summary.y = Convert.ToDecimal(dr[1]);
// color
result.Add(summary);
}
return Json(result, JsonRequestBehavior.AllowGet);
}
此外,这是我的模型
public class itemViewModel
{
public string name { get; set; }
public decimal? y { get; set; }
public string color { get; set; }
}
到目前为止,你尝试过什么!你应该拿出代码!当我是一个tyro并做同样的事情时,我得到的评论比这更糟糕。请拿出你已经尝试 – Mandy8055
https://stackoverflow.com/questions/2109756/how-do-i-get-the-color-from-a-hexadecimal-color-code-using-net – Peter
什么图表控件你使用? - 你在做什么:Winforms,WPF,ASP ..? __Always__正确标记您的问题! – TaW