I have the following situation. I am using a Google API to generate dynamic charts (Google Org Chart), my project is made in asp.net mvc, but this time I only use JS.
The problem that arises is that I need to show an image that I have hosted in my database with the SQL Server manager, the data type is varbinary ...
When I try to show it at the moment I can only show the byte array but I would like to know if someone could support me to make that conversion.
The problem is specifically in the part of var Image.
<!-- Scripts JS -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", { packages: ["orgchart"] });
google.setOnLoadCallback(drawChart);
function drawChart() {
$.ajax({
type: "POST",
url: "/Conocenos/Organigrama_Json",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (dt) {
var dataArray = [];
$.each(dt, function (i, item) {
dataArray.push([item.IDSERVPUB, item.NOMBREPERSONAL, item.NOMBRAMIENTO, item.NIVEL, item.FOTOPERSONAL]);
});
var data = new google.visualization.DataTable();
data.addColumn('string', 'Entity');
data.addColumn('string', 'ReportEntity');
data.addColumn('string', 'ToolTip');
for (var i = 0; i < dataArray.length; i++) {
//no cambiar nombre de variables
var Employee_ID = dataArray[i][0].toString();
var Employee_Name = dataArray[i][1];
var Title = dataArray[i][2];
var ReportTo = dataArray[i][3] != null ? dataArray[i][3].toString() : '';
//necesito convertir este arreglo de bytes en una imagen
var Image = dataArray[i][4]; // solo muestro el arreglo
//si el valor el null que no lo muestre en el diagrama
if (Employee_Name == null) {
Employee_Name = "";
}
data.addRows([[{
v: Employee_ID,
f: Employee_Name + '<br/><b>' + Title + '</b>' + '<br/><b>' + Image
}, ReportTo, Title]]);
}
var chart = new google.visualization.OrgChart($("#chartOrg")[0]);
chart.draw(data, { allowHtml: true });
},
failure: function (dt) {
alert(dt);
},
error: function (dt) {
alert(dt);
}
});
}
</script>