有没有人有关于如何使用Microsoft的内置图表控件制作基本图表的说明的良好链接?
如果可以的话,我想制作一个堆积的条形图。但是,如果不这样做,常规的条形图就足够了。图表的所有数据都是单个SQL调用的结果(一个结果集,一个标签列和3个数据列,如果这有任何区别的话。)我的google-fu让我失望了。提前谢谢。
答案 0 :(得分:26)
文章kesun遗漏的东西是在代码中生成图表:
这是一个涵盖大多数选项的简单示例。
Chart c = new Chart();
c.AntiAliasing = AntiAliasingStyles.All;
c.TextAntiAliasingQuality = TextAntiAliasingQuality.High;
c.Width = 640; //SET HEIGHT
c.Height = 480; //SET WIDTH
ChartArea ca = new ChartArea();
ca.BackColor = Color.FromArgb(248, 248, 248);
ca.BackSecondaryColor = Color.FromArgb(255, 255, 255);
ca.BackGradientStyle = GradientStyle.TopBottom;
ca.AxisY.IsMarksNextToAxis = true;
ca.AxisY.Title = "Gigabytes Used";
ca.AxisY.LineColor = Color.FromArgb(157, 157, 157);
ca.AxisY.MajorTickMark.Enabled = true;
ca.AxisY.MinorTickMark.Enabled = true;
ca.AxisY.MajorTickMark.LineColor = Color.FromArgb(157, 157, 157);
ca.AxisY.MinorTickMark.LineColor = Color.FromArgb(200, 200, 200);
ca.AxisY.LabelStyle.ForeColor = Color.FromArgb(89, 89, 89);
ca.AxisY.LabelStyle.Format = "{0:0.0}";
ca.AxisY.LabelStyle.IsEndLabelVisible = false;
ca.AxisY.LabelStyle.Font = new Font("Calibri", 4, FontStyle.Regular);
ca.AxisY.MajorGrid.LineColor = Color.FromArgb(234, 234, 234);
ca.AxisX.IsMarksNextToAxis = true;
ca.AxisX.LabelStyle.Enabled = false;
ca.AxisX.LineColor = Color.FromArgb(157, 157, 157);
ca.AxisX.MajorGrid.LineWidth = 0;
ca.AxisX.MajorTickMark.Enabled = true;
ca.AxisX.MinorTickMark.Enabled = true;
ca.AxisX.MajorTickMark.LineColor = Color.FromArgb(157, 157, 157);
ca.AxisX.MinorTickMark.LineColor = Color.FromArgb(200, 200, 200);
c.ChartAreas.Add(ca);
Series s = new Series();
s.Font = new Font("Lucida Sans Unicode", 6f);
s.Color = Color.FromArgb(215, 47, 6);
s.BorderColor = Color.FromArgb(159, 27, 13);
s.BackSecondaryColor = Color.FromArgb(173, 32, 11);
s.BackGradientStyle = GradientStyle.LeftRight;
int i = 0;
foreach (DataRow dr in sourceData.Rows)
{
DataPoint p = new DataPoint();
p.XValue = i;
p.YValues = new Double[] { Convert.ToDouble(dr[0]) };
s.Points.Add(p);
i++;
}
c.Series.Add(s);
c.SaveImage(Server.MapPath("~/output.png"), ChartImageFormat.Png);
这会输出到文件,但您可以在HttpHandler中编写它并直接写入响应流。
答案 1 :(得分:15)