0

Can't create standart chart. I tried these methods: http://timbar.blogspot.com/2012/04/creating-chart-programmatically-in-c.html

Chart creating dynamically. in .net, c#

For example code:

private void Form2_Load(object sender, EventArgs e)
    {

var xvals = new[]
            {
                new DateTime(2012, 4, 4), 
                new DateTime(2012, 4, 5), 
                new DateTime(2012, 4, 6), 
                new DateTime(2012, 4, 7)
            };
        var yvals = new[] { 1,3,7,12 };

        // create the chart
        var chart = new Chart();
        chart.Size = new Size(600, 250);

        var chartArea = new ChartArea();
        chartArea.AxisX.LabelStyle.Format = "dd/MMM\nhh:mm";
        chartArea.AxisX.MajorGrid.LineColor = Color.LightGray;
        chartArea.AxisY.MajorGrid.LineColor = Color.LightGray;
        chartArea.AxisX.LabelStyle.Font = new Font("Consolas", 8);
        chartArea.AxisY.LabelStyle.Font = new Font("Consolas", 8);
        chart.ChartAreas.Add(chartArea);

        var series = new Series();
        series.Name = "Series1";
        series.ChartType = SeriesChartType.FastLine;
        series.XValueType = ChartValueType.DateTime;
        chart.Series.Add(series);

        // bind the datapoints
        chart.Series["Series1"].Points.DataBindXY(xvals, yvals);

        // copy the series and manipulate the copy
        chart.DataManipulator.CopySeriesValues("Series1", "Series2");
        chart.DataManipulator.FinancialFormula(
            FinancialFormula.WeightedMovingAverage, 
            "Series2"
        );
        chart.Series["Series2"].ChartType = SeriesChartType.FastLine;

        // draw!
        chart.Invalidate();
}

But it gives me empty form.

How to create chart? Please help!

Community
  • 1
  • 1

1 Answers1

0

You need to add the chart to your form:

this.Controls.Add(chart);

LarsTech
  • 80,625
  • 14
  • 153
  • 225