So lets say I am creating a few charts like so:
Controller:
foreach (var m in model[0].HistoryValues)
{
var chart = new Chart(width: 700, height: 600)
.AddSeries(
name: m.LastUpdateSTR,
chartType: "bar",
xValue: new[] { "Server", "Db", "Tickets" },
yValues: new[] { m.ServerPerformance, m.Databaseperformance, m.SoldTicketsLastUpdate })
.GetBytes("jpg");
m.Bytes = chart;
};
Now I want to display these charts as images in my view:
@foreach (var t in Model[0].HistoryValues)
{
<img src="@CalculationHandler.getImage(t.Bytes)" alt="Chart Image" />
}
The getImage method:
public static FileContentResult getImage(byte[] bytes)
{
return new FileContentResult(bytes, "image/jpg");
}
The result :
Other attempts:
This gave me a serverError, sadly I do not know why since I could not debug the getImage method when doing this.
@foreach (var t in Model[0].HistoryValues)
{
<img src="@Url.Action("getImage", "OverWatch", new { Mybytes= t.Bytes })" alt="Chart Image" />
}
This gave me the same result as the first code in this post but again I could not debug the getImage method,
@foreach (var m in Model[0].HistoryValues)
{
<img src="@Html.Action("getImage", "OverWatch", new { Mybytes= m.Bytes })" alt="Chart Image" />
}
NOTE:
I do not want to save any images to the project. This application is intented to be used by multiple users and I do not want to flud it with numerous pictures.
How do I solve this?
EDIT:
When using the write method like so:
Controller:
foreach (var m in model[0].HistoryValues)
{
Chart chart2 = new Chart(width: 700, height: 600)
.AddSeries(
name: m.LastUpdateSTR,
chartType: "bar",
xValue: new[] { "Server", "Db", "Tickets" },
yValues: new[] { m.ServerPerformance, m.Databaseperformance, m.SoldTicketsLastUpdate })
.Write();
m.Bytes =chart2.GetBytes("jpg");
};
This shows only one chart , Also my layout does not get displayed when doing this.
EDIT 2:
Tried this:
var chart = new Chart(width: 700, height: 600)
.AddSeries(
name: m.LastUpdateSTR,
chartType: "bar",
xValue: new[] { "Server", "Db", "Tickets" },
yValues: new[] { m.ServerPerformance, m.Databaseperformance, m.SoldTicketsLastUpdate })
.GetBytes("jpg");
string t = Convert.ToBase64String(chart);
t = t.Replace('-', '+');
t = t.Replace('_', '/');
m.Bytes = Convert.FromBase64String(t);
View:
@foreach (var m in Model[0].HistoryValues)
{
<img src="@Url.Action("getImage", "OverWatch", new { Mybytes= m.Bytes })" alt="Person Image" />
}
Result.