本文整理汇总了C#中Chart类的典型用法代码示例。如果您正苦于以下问题:C# Chart类的具体用法?C# Chart怎么用?C# Chart使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Chart类属于命名空间,在下文中一共展示了Chart类的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: ReturnChart
private FileContentResult ReturnChart(Chart chart)
{
var stream = new MemoryStream();
chart.SaveImage(stream, ChartImageFormat.Png);
stream.Position = 0;
return File(stream.GetBuffer(), "image/png");
}
示例3: LineChart
public static Chart LineChart()
{
Chart chart = new Chart(ChartType.Line);
Series series = chart.SeriesCollection.AddSeries();
series.Name = "Series 1";
series.Add(new double[] { 1, 5, -3, 20, 11 });
series = chart.SeriesCollection.AddSeries();
series.Name = "Series 2";
series.Add(new double[] { 22, 4, 12, 8, 12 });
series = chart.SeriesCollection.AddSeries();
series.Name = "Series 3";
series.Add(new double[] { 12, 14, -3, 18, 1 });
chart.XAxis.MajorTickMark = TickMarkType.Outside;
chart.XAxis.Title.Caption = "X-Axis";
chart.YAxis.MajorTickMark = TickMarkType.Outside;
chart.YAxis.Title.Caption = "Y-Axis";
chart.YAxis.HasMajorGridlines = true;
chart.PlotArea.LineFormat.Color = XColors.DarkGray;
chart.PlotArea.LineFormat.Width = 1;
chart.PlotArea.LineFormat.Visible = true;
chart.Legend.Docking = DockingType.Bottom;
chart.Legend.LineFormat.Visible = true;
XSeries xseries = chart.XValues.AddXSeries();
xseries.Add("A", "B", "C", "D", "E", "F");
return chart;
}
示例4: Create_LinearChart_WithYAxis
public void Create_LinearChart_WithYAxis()
{
var chart = new Chart<DateTime, double>();
var linearY = chart.GetLinearY(10d);
Assert.NotNull(linearY);
}
示例5: BindData
public static void BindData(Chart chart, string prvName, object context, string[] seriesExpr, string labelExpr, string labelLookupName)
{
var prv = WebManager.GetService<IProvider<object,object>>(prvName);
var ognlContext = new Dictionary<string,object>();
ognlContext["data"] = prv.Provide(context);
var ognlExpr = new NReco.OGNL.EvalOgnl();
int seriesIdx = 0;
foreach (var expr in seriesExpr) {
var dataset = (IEnumerable)ognlExpr.Eval( expr, ognlContext );
var series = chart.Series[seriesIdx];
foreach (var val in dataset) {
var decVal = Convert.ToDecimal(val);
series.Points.AddY(decVal);
}
seriesIdx++;
}
/*if (!String.IsNullOrEmpty(labelExpr)) {
var labels = (IEnumerable)ognlExpr.Eval( labelExpr, ognlContext );
var labelsList = new List<string>();
var labelPrv = String.IsNullOrEmpty(labelLookupName) ? null : WebManager.GetService<IProvider<object,string>>(labelLookupName);
foreach (var lbl in labels) {
labelsList.Add( labelPrv!=null ? labelPrv.Provide(lbl) : Convert.ToString(lbl) );
}
res += "&"+labelParam+String.Join("|", labelsList.ToArray() );
}*/
}
示例6: Input
public ActionResult Input()
{
List<string> xval = new List<string>();
List<string> yval = new List<string>();
List<string> yval2 = new List<string>();
foreach (var points in db.Users.ToList().OrderByDescending(c => c.Win).Take(9))
{
xval.Add(points.Name);
yval.Add(points.Input.ToString());
yval2.Add(points.Win.ToString());
}
string[] _xval = xval.ToArray();
string[] _yval = yval.ToArray();
string[] _yval2 = yval2.ToArray();
var chartsPoint = new Chart(width: 1000, height: 400, theme: ChartTheme.Blue) //,theme: ChartTheme.Blue
.AddSeries(
name: "Buy-In",
xValue: _xval,
yValues: _yval
)
.AddSeries(
name:"Gewonnen",
xValue: _xval,
yValues: _yval2)
.AddLegend();
return File(chartsPoint.GetBytes("png"), "image/png");
}
示例7: 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);
}
示例8: 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");
}
示例9: GenerateBarChart
public static Chart GenerateBarChart(IList<LogStatistic<DateTime, int>> values, int width, int height)
{
Chart ch = new Chart();
ch.ChartAreas.Add(new ChartArea());
List<string> dates = new List<string>();
List<int> counts = new List<int>();
foreach (var tuple in values)
{
dates.Add(tuple.Key.Date.ToShortDateString());
counts.Add(tuple.Value);
}
int[] yval = counts.ToArray();
// Initialize an array of strings
string[] xval = dates.ToArray();
Series series = new Series("Default");
series.ChartType = SeriesChartType.Bar;
// Add series into the chart's series collection
ch.Series.Add(series);
// Bind the double array to the Y axis points of the Default data series
ch.Series["Default"].Points.DataBindXY(xval, yval);
ch.Width = width;
ch.Height = height;
return ch;
}
示例10: AddChartData
protected virtual void AddChartData(Chart chart, List<Series> data)
{
foreach (Series series in data)
{
chart.Series.Add(series);
}
}
示例11: GetPieChart
public ActionResult GetPieChart()
{
int[] ranges = { 4, 8, 12 };
var query = from value in uploadDataMgr.GetUploadedLive().ToList()
.Where(p => p.ScoreTotal != null)
.Select(p => p.ScoreTotal)
group value by ranges.Where(x => value >= x)
.DefaultIfEmpty()
.Last() into groups
select new { Key = groups.Key, Values = groups };
Dictionary<string, int> dictRiskCat = new Dictionary<string, int>();
foreach (var group in query)
{
if (group.Key == 0)
dictRiskCat.Add("Low Risk", group.Values.Count());
else if (group.Key == 4)
dictRiskCat.Add("Medium Risk", group.Values.Count());
else if (group.Key == 8)
dictRiskCat.Add("High Risk", group.Values.Count());
}
var key = new Chart(width: 300, height: 300)
.AddTitle("Risk Summary")
.AddSeries(
chartType: "Pie",
name: "Risk Summary",
xValue: dictRiskCat.Keys,
yValues: dictRiskCat.Values);
return File(key.ToWebImage().GetBytes(), "image/jpeg");
}
示例12: CreateChartByMonthPerYear
public ActionResult CreateChartByMonthPerYear(int year)
{
try
{
List<int> lstArticlesCount = articleManager.GetArticlesPerMonth(year);
string temp = @"<Chart BackColor=""LightGray"" ForeColor=""LightBlue"">
<ChartAreas>
<ChartArea Name=""Default"" _Template_=""All"">
<AxisY>
<LabelStyle Font=""Verdana, 15px"" />
</AxisY>
<AxisX LineColor=""64, 64, 64, 64"" Interval=""1"">
<LabelStyle Font=""Verdana, 14px"" />
</AxisX>
</ChartArea>
</ChartAreas>
</Chart>";
Chart chartPerMonth = new Chart(width: 1000, height: 500, theme: temp).AddTitle(year.ToString()).AddSeries(chartType: "column", xValue: new[] { "Janury", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }, yValues: lstArticlesCount).Write("bmp");
return null;
}
catch (Exception e)
{
ViewBag.ErrorTitle = "Server Error";
ViewBag.ErrorDescription = "Please try again later";
return View("~/Views/Shared/ErrorPage.cshtml");
}
}
示例13: InitializeBarGraph
private static Chart InitializeBarGraph(SeriesCollection seriesCollection, string yAxisTitle)
{
var chart = new Chart();
//chart.Title = "Burndown";
chart.Type = ChartType.Combo;
chart.TempDirectory = VirtualPathUtility.ToAbsolute("~/file/chart");
chart.SeriesCollection.Add(seriesCollection);
chart.YAxis.Label.Text = yAxisTitle;
chart.YAxis.Label.Color = System.Drawing.ColorTranslator.FromHtml("#CCCCCC");
chart.YAxis.DefaultTick.Label.Color = System.Drawing.ColorTranslator.FromHtml("#CCCCCC");
chart.XAxis.DefaultTick.Label.Color = System.Drawing.ColorTranslator.FromHtml("#CCCCCC");
chart.LegendBox.Visible = false;
chart.BorderStyle = System.Web.UI.WebControls.BorderStyle.None;
chart.TitleBox.Visible = false;
chart.Background.Color = System.Drawing.ColorTranslator.FromHtml("#333333");
chart.DefaultSeries.Element.Color = System.Drawing.ColorTranslator.FromHtml("#1B12A6");
chart.DefaultElement.Color = System.Drawing.ColorTranslator.FromHtml("#1B12A6");
chart.Width = new System.Web.UI.WebControls.Unit(600, System.Web.UI.WebControls.UnitType.Pixel);
chart.Height = new System.Web.UI.WebControls.Unit(400, System.Web.UI.WebControls.UnitType.Pixel);
chart.Font.Name = "Helvetica";
chart.Font.Size = new System.Web.UI.WebControls.FontUnit(24, System.Web.UI.WebControls.UnitType.Pixel);
chart.YAxis.Label.Font = new System.Drawing.Font("Helvetica", 8);
chart.YAxis.DefaultTick.Label.Font = new System.Drawing.Font("Helvetica", 8);
chart.XAxis.DefaultTick.Label.Font = new System.Drawing.Font("Helvetica", 8);
//NOTE: needed to do this for the old version of .net charting (3.4).
chart.FileManager.TempDirectory = VirtualPathUtility.ToAbsolute("~/file/chart");
chart.FileManager.SaveImage(chart.GetChartBitmap());
//chart.FileManager.FileName = chart.FileManager.TempDirectory + "/" + chart.FileManager.FileName + ".png";
return chart;
}
示例14: ChartActionResult
public ChartActionResult(Chart chart, ChartImageFormat imageFormat = ChartImageFormat.Png)
{
if (chart == null) { throw new ArgumentNullException("chart"); }
_chart = chart;
_imageFormat = imageFormat;
}
示例15: ConstructorLoadsTheme
public void ConstructorLoadsTheme() {
//Vanilla theme
/*
* <Chart Palette="SemiTransparent" BorderColor="#000" BorderWidth="2" BorderlineDashStyle="Solid">
<ChartAreas>
<ChartArea _Template_="All" Name="Default">
<AxisX>
<MinorGrid Enabled="False" />
<MajorGrid Enabled="False" />
</AxisX>
<AxisY>
<MajorGrid Enabled="False" />
<MinorGrid Enabled="False" />
</AxisY>
</ChartArea>
</ChartAreas>
</Chart>
*/
var chart = new Chart(GetContext(), GetVirtualPathProvider(), 100, 100, theme: ChartTheme.Vanilla);
AssertBuiltChartAction(chart, c => {
Assert.AreEqual(c.Palette, DV.ChartColorPalette.SemiTransparent);
Assert.AreEqual(c.BorderColor, Color.FromArgb(0, Color.Black));
Assert.AreEqual(1, c.ChartAreas.Count);
Assert.IsFalse(c.ChartAreas[0].AxisX.MajorGrid.Enabled);
Assert.IsFalse(c.ChartAreas[0].AxisY.MinorGrid.Enabled);
});
}