ASP.NET图:上设置X和Y轴的字体 [英] ASP.NET Chart: setting the fonts on X and Y axis
本文介绍了ASP.NET图:上设置X和Y轴的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑到构建一个ASP.NET图图像的ASP.NET MVC控制器的方法。
公共FileStreamResult MAKEIMG(IEnumerable的< MyObj中>统计)
{
图柱状图= BARCHART(400,300); 系列系列1 =新系列(系列1);
series1.ChartArea =CA1;
series1.ChartType = SeriesChartType.Column;
series1.IsValueShownAsLabel = TRUE;
series1.Font =新的字体(宋体,9F,FontStyle.Regular); barchart.Series.Add(系列1); //设置图表数据源
barchart.DataSource =统计信息; X和Y值//设置系列成员的名字
barchart.Series [系列1] XValueMember =FriendlyDate。
barchart.Series [系列1] YValueMembers =NumRecords。 //数据绑定到所选择的数据源
barchart.DataBind(); MemoryStream的毫秒=新的MemoryStream();
barchart.SaveImage(MS,ChartImageFormat.Png);
ms.Seek(0,SeekOrigin.Begin); 返回新FileStreamResult(MS,图像/ PNG);
}
图片在一个没有吸引力的方式呈现:
问:我如何设置字体编程为:
- X和Y轴标签 - 即0到35的Y和X上的日期
- 数据 - 即12,0,0,3,6
解决方案
chart.ChartAreas [0] .AxisX.LabelStyle.Font
chart.ChartAreas [0] .AxisY.LabelStyle.Font
是你需要设置坐标轴的字体属性。
Consider an ASP.NET MVC controller method that builds an ASP.NET Chart image.
public FileStreamResult MakeImg(IEnumerable<MyObj> stats)
{
Chart barchart = BarChart(400, 300);
Series series1 = new Series("Series1");
series1.ChartArea = "ca1";
series1.ChartType = SeriesChartType.Column;
series1.IsValueShownAsLabel = true;
series1.Font = new Font("Verdana", 9f, FontStyle.Regular);
barchart.Series.Add(series1);
// Set chart data source
barchart.DataSource = stats;
// Set series members names for the X and Y values
barchart.Series["Series1"].XValueMember = "FriendlyDate";
barchart.Series["Series1"].YValueMembers = "NumRecords";
// Data bind to the selected data source
barchart.DataBind();
MemoryStream ms = new MemoryStream();
barchart.SaveImage(ms, ChartImageFormat.Png);
ms.Seek(0, SeekOrigin.Begin);
return new FileStreamResult(ms, "image/png");
}
The image is rendered in an unattractive manner:
Question: How can I set the font programmatically for the:
- X and Y axis labels - i.e. 0 through 35 on Y, and the dates on X
- data - i.e. 12, 0, 0, 3, 6 ?
解决方案
chart.ChartAreas[0].AxisX.LabelStyle.Font
chart.ChartAreas[0].AxisY.LabelStyle.Font
is the property you need to set the font for the Axes.
这篇关于ASP.NET图:上设置X和Y轴的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文