开发者

How can I use system.web.ui.datavisualization.charting.chart to make a chart? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If开发者_JS百科 you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

Does anyone have a good link for instructions on how to make a basic chart with Microsoft's built-in chart control?

I'd like to make a stacked bar chart, if I could. But, failing that, a regular bar chart would suffice. All the data for the chart is the result of a single SQL call (one result set, 1 label column and 3 data columns, if that makes any difference.)

My google-fu is failing me. Thanks in advance.


Something that the article kesun left out was generating the chart in code:

Here's a quick example that covers the majority of the options.

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);

This outputs to a file, but you could write this in an HttpHandler and write directly to the response stream.


My google-fu turned out these two guides that I used before :-)

MS Chart ASP.Net Part 1

MS Chart ASP.Net Part 2

HTH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜