本文整理汇总了C#中Chart.SaveImage方法的典型用法代码示例。如果您正苦于以下问题:C# Chart.SaveImage方法的具体用法?C# Chart.SaveImage怎么用?C# Chart.SaveImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chart
的用法示例。
在下文中一共展示了Chart.SaveImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSaleRankChart
public FileResult GetSaleRankChart()
{
var gQuery = (from m in orderDetailRepo.GetWithFilterAndOrder()
group m by m.Meal.MealName into g
orderby g.Sum(item => item.Quantity * 1) descending
select new Group<string, int> { Key = g.Key, Value = g.Sum(item=> item.Quantity * 1) })
.Take(5);
var chart = new Chart();
chart.ChartAreas.Add(new ChartArea("Default"));
chart.Width = 500;
chart.Height = 400;
chart.ChartAreas["Default"].Area3DStyle.Enable3D = true;
chart.ChartAreas["Default"].Area3DStyle.Inclination = 15;
chart.ChartAreas["Default"].Area3DStyle.Rotation = 15;
chart.Series.Add(new Series("Data"));
foreach (var item in gQuery)
{
chart.Series["Data"].Points.AddXY(item.Key, item.Value);
}
System.IO.MemoryStream ms = new System.IO.MemoryStream();
chart.SaveImage(ms, ChartImageFormat.Png);
ms.Seek(0, System.IO.SeekOrigin.Begin);
return File(ms, "image/png");
}
示例2: ChartToBytes
public static byte[] ChartToBytes(Chart ch)
{
var fs = new FileStream(@"D:\serializedImage.jpg", FileMode.Create);
ch.SaveImage(fs, ChartImageFormat.Jpeg);
fs.Close();
var ms = new MemoryStream();
ch.SaveImage(ms, ChartImageFormat.Jpeg);
return ms.GetBuffer();
}
示例3: BuildChart
public MemoryStream BuildChart(int? type, IDictionary<string, float> dataPoints)
{
// default to line
var chartType = type == null ? SeriesChartType.Line : (SeriesChartType)type;
var chart = new Chart();
// configure your chart area (dimensions, etc) here.
var area = new ChartArea();
chart.ChartAreas.Add(area);
TickMark tm = new TickMark();
// create and customize your data series.
var series = new Series();
foreach (var item in dataPoints)
{
series.Points.AddXY(item.Key, item.Value);
}
//series.Label = "#PERCENT{P0}";
series.Font = new Font("Segoe UI", 8.0f, FontStyle.Bold);
series.ChartType = chartType;
series["PieLabelStyle"] = "Outside";
chart.Series.Add(series);
var returnStream = new MemoryStream();
chart.ImageType = ChartImageType.Png;
chart.SaveImage(returnStream);
returnStream.Position = 0;
return returnStream;
}
示例4: ReturnChart
private FileContentResult ReturnChart(Chart chart)
{
var stream = new MemoryStream();
chart.SaveImage(stream, ChartImageFormat.Png);
stream.Position = 0;
return File(stream.GetBuffer(), "image/png");
}
示例5: Weight
public FileStreamResult Weight(int timeFrame = 0)
{
var weightChart = new Chart
{
Width = 600,
Height = 300
};
var weights = _repository.GetWeightsByUser(User.Identity.Name);
if (timeFrame > 0)
{
timeFrame = timeFrame * -1;
var pastDate = DateTime.Today.AddMonths(timeFrame);
weights = weights.Where(w => w.WeightDate > pastDate);
}
weights = weights.OrderBy(w => w.WeightDate);
var builder = new DailyWeightChartBuilder(weights.ToList(), weightChart);
builder.BuildChart();
// Save the chart to a MemoryStream
var imgStream = new MemoryStream();
weightChart.SaveImage(imgStream, ChartImageFormat.Png);
imgStream.Seek(0, SeekOrigin.Begin);
// Return the contents of the Stream to the client
return File(imgStream, "image/png");
}
示例6: CreateChart
public static void CreateChart(string imagePath,string name, IEnumerable<BenchResult> results, Func<BenchResult,double> selector)
{
Chart chart = new Chart();
chart.Width = 500;
chart.Height = 400;
chart.Titles.Add(name);
var area = new ChartArea("Default");
chart.ChartAreas.Add(area);
var series = new Series("Default");
chart.Series.Add(series);
area.AxisX.LabelAutoFitStyle = LabelAutoFitStyles.LabelsAngleStep90;
area.AxisX.LabelStyle.TruncatedLabels = false;
area.AxisX.Interval = 1;
series.ChartType = SeriesChartType.Column;
series.IsValueShownAsLabel = true;
series.XValueType = ChartValueType.String;
series.YValueType = ChartValueType.Int32;
foreach(var r in results.OrderBy( r => selector(r)))
{
DataPoint point = new DataPoint();
point.SetValueXY(r.Serializer.Replace("Adapter",""),(int)Math.Round(selector(r)));
point.AxisLabel = r.Serializer.Replace("Adapter", "");
series.Points.Add(point);
}
chart.SaveImage(imagePath, ChartImageFormat.Png);
}
示例7: Details
public ActionResult Details(int width = 500, int height = 500)
{
var chart = new Chart { Height = height, Width = width };
var chartArea = new ChartArea("Area1")
{
AxisX = { Interval = 1 },
Area3DStyle = { Enable3D = true },
BackColor = Color.Transparent
};
chart.ChartAreas.Add(chartArea);
chart.BackColor = Color.Transparent;
var seriescountAll = new Series("项目统计");
var countAll =
_iProjectInfoStateService.GetAll()
.Select(a => new { Key = a.ProjectInfoStateName, Count = a.ProjectInfos.Count(b => !b.Deleted) });
seriescountAll.ChartArea = "Area1";
seriescountAll.IsVisibleInLegend = true;
seriescountAll.IsValueShownAsLabel = true;
seriescountAll.Label = "#VALX #VALY";
seriescountAll.Points.DataBind(countAll, "Key", "Count", "");
seriescountAll.ChartType = SeriesChartType.Funnel;
chart.Series.Add(seriescountAll);
var imageStream = new MemoryStream();
chart.SaveImage(imageStream, ChartImageFormat.Png);
imageStream.Position = 0;
return new FileStreamResult(imageStream, "image/png");
}
示例8: InventoryChart
public InventoryChart(InventoryChartType InventoryChartType, InventoryData InventoryData, string Title)
{
chart = new Chart();
chart.Width = 700;
chart.Height = 300;
chart.BackColor = Color.FromArgb(211, 223, 240);
chart.BorderlineDashStyle = ChartDashStyle.Solid;
chart.BackSecondaryColor = Color.White;
chart.BackGradientStyle = GradientStyle.TopBottom;
chart.BorderlineWidth = 1;
chart.BorderlineColor = Color.FromArgb(26, 59, 105);
chart.RenderType = RenderType.BinaryStreaming;
chart.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
chart.AntiAliasing = AntiAliasingStyles.All;
chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;
chart.Titles.Add(CreateTitle(Title));
chart.Palette = ChartColorPalette.BrightPastel;
chart.PaletteCustomColors = Settings.GetChartColorPaletteColors(chart.Palette);
//chart.ApplyPaletteColors();
switch (InventoryData.InventoryCostGroup)
{
case InventoryCostGroup.InventoryType:
chart.Legends.Add(CreateLegend());
for (int intCounter = 0; intCounter < InventoryData.SeriesDataSets.Count; intCounter++)
chart.Series.Add(CreatePerformanceSeries(InventoryData.SeriesDataSets[intCounter], SeriesChartType.Line, InventoryData.SeriesDataSets[intCounter][0].InventoryType));
break;
case InventoryCostGroup.Warehouse:
chart.Legends.Add(CreateLegend());
for (int intCounter = 0; intCounter < InventoryData.SeriesDataSets.Count; intCounter++)
chart.Series.Add(CreatePerformanceSeries(InventoryData.SeriesDataSets[intCounter], SeriesChartType.Line, InventoryData.SeriesDataSets[intCounter][0].Warehouse));
break;
case InventoryCostGroup.Purchased:
case InventoryCostGroup.Manufactured:
case InventoryCostGroup.WIP:
chart.Series.Add(CreatePerformanceSeries(InventoryData.CollectionData, SeriesChartType.Line, InventoryData.CollectionDataName));
break;
case InventoryCostGroup.None:
chart.Legends.Add(CreateLegend());
switch (InventoryChartType)
{
case InventoryChartType.CompareByWarehouse:
for (int intCounter = 0; intCounter < InventoryData.SeriesDataSets.Count; intCounter++)
chart.Series.Add(CreateSeries(InventoryData.SeriesDataSets[intCounter], SeriesChartType.Column, "InventoryType", chart.PaletteCustomColors[intCounter], InventoryData.SeriesDataSets[intCounter][0].Warehouse));
break;
case InventoryChartType.CompareByInventoryType:
for (int intCounter = 0; intCounter < InventoryData.SeriesDataSets.Count; intCounter++)
chart.Series.Add(CreateSeries(InventoryData.SeriesDataSets[intCounter], SeriesChartType.Column, "Warehouse", chart.PaletteCustomColors[intCounter], InventoryData.SeriesDataSets[intCounter][0].InventoryType));
break;
}
break;
}
chart.ChartAreas.Add(CreateChartArea());
chartStream = new MemoryStream();
chart.SaveImage(chartStream);
}
示例9: Details
public FileResult Details(int width = 1000, int height = 618)
{
var sysUserLog = _sysUserLogService.GetAllEnt();
var sysLog = _sysLogService.GetAllEnt();
var chart = new Chart { Height = height, Width = width };
var chartArea = new ChartArea("Area1") {AxisX = {Interval = 1}};
chart.ChartAreas.Add(chartArea);
var legend = new Legend();
chart.Legends.Add(legend);
var seriescountAll = new Series("使用次数");
var countAll =
sysUserLog.GroupBy(a => EntityFunctions.TruncateTime(a.CreatedDate))
.Select(a => new { Key = a.Key.Value, Count = a.Count() })
.OrderBy(a => a.Key);
seriescountAll.ChartArea = "Area1";
seriescountAll.IsVisibleInLegend = true;
seriescountAll.IsValueShownAsLabel = true;
seriescountAll.Points.DataBind(countAll, "Key", "Count", "");
seriescountAll.ChartType = SeriesChartType.Column;
chart.Series.Add(seriescountAll);
var seriescountUser = new Series("登陆用户数量");
var countUser =
sysUserLog.GroupBy(a => EntityFunctions.TruncateTime(a.CreatedDate)).Select(
a => new { Key = a.Key.Value, Count = a.Select(c => c.SysUserId).Distinct().Count() })
.OrderBy(a => a.Key);
seriescountUser.ChartArea = "Area1";
seriescountUser.IsVisibleInLegend = true;
seriescountUser.IsValueShownAsLabel = true;
seriescountUser.Points.DataBind(countUser, "Key", "Count", "");
seriescountUser.ChartType = SeriesChartType.Column;
chart.Series.Add(seriescountUser);
var seriessysLogChart = new Series("系统日志");
var sysLogChart =
sysLog.GroupBy(a => EntityFunctions.TruncateTime(a.CreatedDate))
.Select(a => new { Key = a.Key.Value, Count = a.Count() })
.OrderBy(a => a.Key);
seriessysLogChart.ChartArea = "Area1";
seriessysLogChart.IsVisibleInLegend = true;
seriessysLogChart.IsValueShownAsLabel = true;
seriessysLogChart.Points.DataBind(sysLogChart, "Key", "Count", "");
seriessysLogChart.ChartType = SeriesChartType.Column;
chart.Series.Add(seriessysLogChart);
var imageStream = new MemoryStream();
chart.SaveImage(imageStream, ChartImageFormat.Png);
imageStream.Position = 0;
return new FileStreamResult(imageStream, "image/png");
}
示例10: GetGenresChart
public ActionResult GetGenresChart()
{
try
{
using (DataModels.dbContext context = new DataModels.dbContext())
{
var genresq = (from link in context.movie_genre
join genres in context.genres on link.genre_id equals genres.id
group link.genre_id by genres.name into genre
select new
{
genreName = genre.Key,
genreCount = genre.Count()
});
List<string> genreName = new List<string>();
List<int> genreCount = new List<int>();
foreach (var list in genresq)
{
genreName.Add(list.genreName);
genreCount.Add(list.genreCount);
}
context.Dispose();
Chart chart = new Chart();
chart.ChartAreas.Add(new ChartArea());
chart.Width = 1024;
chart.Height = 768;
chart.Series.Add(new Series("Genres"));
chart.Series["Genres"].ChartType = SeriesChartType.Pie;
chart.Series["Genres"].Points.DataBindXY(
genresq.Select(g => g.genreName.ToString()).ToArray(),
genresq.Select(g => g.genreCount).ToArray());
chart.Series["Genres"].Label = "#PERCENT{P0} #VALX";
chart.Series["Genres"]["PieLabelStyle"] = "Outside";
chart.Series["Genres"]["PieLineColor"] = "Black";
MemoryStream ms = new MemoryStream();
chart.SaveImage(ms, ChartImageFormat.Png);
return File(ms.ToArray(), "image/png");
}
}
catch (Exception e)
{
return null;
}
}
示例11: RenderContents
protected override void RenderContents()
{
HtmlGenericControl contents = new HtmlGenericControl("div");
contents.ID = "contents";
HtmlGenericControl h1 = new HtmlGenericControl("h1");
h1.InnerText = "Requests by Browser Type";
contents.Controls.Add(h1);
Chart browsersChart = new Chart();
browsersChart.ImageStorageMode = ImageStorageMode.UseHttpHandler;
browsersChart.Width = 500;
browsersChart.Height = 500;
browsersChart.Titles.Add("Requests by Browser Type");
//contents.Controls.Add(browsersChart);
// This is the most important part, and the departure from using any custom classes or Futures library.
//// Simply use a MemoryStream to save the chart.
//MemoryStream imageStream = new MemoryStream();
//browsersChart.SaveImage(imageStream, ChartImageFormat.Png);
//// Reset the stream’s pointer back to the start of the stream.
//imageStream.Seek(0, SeekOrigin.Begin);
// return the normal FileResult available in the current release of MVC
browsersChart.RenderType = RenderType.ImageTag;
browsersChart.ImageLocation = "~/MyChart.png";
browsersChart.SaveImage(Server.MapPath("~/MyChart.png"), ChartImageFormat.Png);
HtmlImage chart = new HtmlImage();
chart.ID = "browsers chart";
chart.Src = Request.ApplicationPath + "/MyChart.png";
chart.Height = 500;
chart.Width = 500;
contents.Controls.Add(chart);
//contents.Controls.Add(browsersChart);
//browsersChart.SaveImage(Response.OutputStream, ChartImageFormat.Png);
//Response.End();
_body.Controls.Add(contents);
}
示例12: GetChart
/// <summary>
/// Can be placed at any place...
/// Depending on type of Chart
/// </summary>
/// <param name="title"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="xNames"></param>
/// <param name="yValues"></param>
/// <returns></returns>
private byte[] GetChart(string title, double? width, double? height, string[] xNames, double[] yValues)
{
var reportData = new List<string>();
byte[] data = new byte[256];
Chart chart = new Chart();
chart.Width = new Unit(width.Value);
chart.Height = new Unit(height.Value);
chart.Titles.Add(title);
Series pieSeries = new Series();
pieSeries.ChartType = SeriesChartType.Pie;
pieSeries.Points.DataBindXY(xNames, yValues);
pieSeries.Points[4]["Exploded"] = "True";
chart.Series.Add(pieSeries);
chart.ChartAreas.Add("basic");
chart.ChartAreas[0].Area3DStyle = new ChartArea3DStyle() { Enable3D=true};
MemoryStream ms = new MemoryStream();
chart.SaveImage(ms);
data = ms.GetBuffer();
return data;
}
示例13: GenerateChart
public ActionResult GenerateChart()
{
DataModels.d8u6uelvine6d6DB database = new DataModels.d8u6uelvine6d6DB();
var genresList = (from movie_genre in database.movie_genre
join genre in database.genres on movie_genre.genre_id equals genre.id
group movie_genre.genre_id by genre.name into genres
select new
{
genreName = genres.Key,
genreCount = genres.Count()
});
Chart chart = new Chart();
chart.ChartAreas.Add(new ChartArea());
chart.Series.Add(new Series("Data"));
chart.Legends.Add(new Legend("Genres"));
chart.Series["Data"].ChartType = SeriesChartType.Pie;
chart.Series["Data"]["PieLabelStyle"] = "Outside";
chart.Series["Data"]["PieLineColor"] = "Black";
chart.Width = 640;
chart.Height = 480;
foreach (var elem in genresList)
{
int point = chart.Series["Data"].Points.AddXY(elem.genreName, elem.genreCount);
DataPoint pt = chart.Series["Data"].Points[point];
pt.LegendText = "#VALX: #VALY";
}
chart.Series["Data"].Label = "#PERCENT{P0}";
chart.Series["Data"].ChartType = SeriesChartType.Pie;
chart.Series["Data"]["PieLabelStyle"] = "Outside";
chart.Series["Data"].Legend = "Genres";
chart.Legends["Genres"].Docking = Docking.Bottom;
var returnStream = new MemoryStream();
chart.ImageType = ChartImageType.Png;
chart.SaveImage(returnStream);
returnStream.Position = 0;
return new FileStreamResult(returnStream, "image/png");
}
示例14: CreateChart
public FileResult CreateChart(string itemName, string leagueName)
{
ItemsDataContext itemsDB = new ItemsDataContext(DATA_CONNECTION_STRING);
var result = from item in itemsDB.Items
where item.Name == itemName &&
item.League == leagueName
orderby item.Timestamp ascending
select item;
Chart chart = new Chart();
chart.Width = 900;
chart.Height = 600;
chart.BackColor = Color.LightGray;
chart.BorderlineDashStyle = ChartDashStyle.Solid;
chart.BorderlineWidth = 1;
chart.Palette = ChartColorPalette.BrightPastel;
chart.BorderlineColor = Color.Black;
chart.RenderType = RenderType.BinaryStreaming;
chart.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
chart.AntiAliasing = AntiAliasingStyles.All;
chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;
chart.Titles.Add(CreateTitle(string.Format("{0} in {1} league", itemName, leagueName)));
chart.Legends.Add(new Legend());
chart.Series.Add(CreateSeries("Items listed", result, x => (float)x.MaxPrice, Color.Blue));
chart.Series.Add(CreateSeries("Median Price", result, x => (float)x.MedianPrice, Color.Green));
chart.Series.Add(CreateSeries("Mean Price", result, x => (float)x.MeanPrice, Color.Orange));
chart.Series.Add(CreateSeries("Min Price", result, x => (float)x.MinPrice, Color.Violet));
chart.Series.Add(CreateSeries("Max Price", result, x => (float)x.MaxPrice, Color.Red));
chart.ChartAreas.Add(CreateChartArea("Items listed", "Number of listings"));
chart.ChartAreas.Add(CreateChartArea("Median Price"));
chart.ChartAreas.Add(CreateChartArea("Mean Price"));
chart.ChartAreas.Add(CreateChartArea("Min Price"));
chart.ChartAreas.Add(CreateChartArea("Max Price"));
MemoryStream ms = new MemoryStream();
chart.SaveImage(ms);
return File(ms.GetBuffer(), @"image/png");
}
示例15: CreateColumnChart
/**
* Create bar chart
* **/
public FileResult CreateColumnChart(IList<IndexChartModels> indexList, IList<MoneyChartModels> moneyList, int width, int height, string title)
{
SeriesChartType chartType = SeriesChartType.Column;
Chart chart = new Chart();
chart.Width = width; // 900;
chart.Height = height; //300;
//chart.BackColor = Color.FromArgb(211, 223, 240);
chart.BackColor = Color.FromArgb(128, 192, 219);
chart.BorderlineDashStyle = ChartDashStyle.Solid;
chart.BackSecondaryColor = Color.White;
chart.BackGradientStyle = GradientStyle.TopBottom;
chart.BorderlineWidth = 1;
chart.Palette = ChartColorPalette.BrightPastel;
chart.BorderlineColor = Color.FromArgb(26, 59, 105);
chart.RenderType = RenderType.BinaryStreaming;
chart.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
chart.AntiAliasing = AntiAliasingStyles.All;
chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;
MemoryStream ms = new MemoryStream();
chart.Titles.Add(this.CreateColumnTitle(title));
//chart.Legends.Add(this.CreateLegend());
chart.Series.Add(this.CreateColumnSeries(indexList, chartType));
if (this.isShowMoneyLine(moneyList))
{
chart.Series.Add(this.CreateLineSeries(moneyList, SeriesChartType.Line));
}
// *** The following code should not normally be modified ***
chart.ChartAreas.Add(this.CreateColumnChartArea());
chart.SaveImage(ms);
return File(ms.GetBuffer(), @"image/png");
}