I have got an Diagram example that is supposed to draw a diagram that I have on a picture.
The code compiles but cant understand how to trigger this code for example in the button click event that I have set up.

Perheps there is any C# code basics of how to execute this code to Create a Chart.

I have done a guess of code in the button click event to execute something but it seems that .CreateChart() needs arguments inside the (). The compiler shows (ref Chart Chart1) when entering the first leftside paranthes but that doesn´t compile

Any idéas of how to execute this so the chart will be drawn. The code should be right.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.ComponentModel;
using dotnetCHARTING.WinForms;

namespace Charts
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            RateCharts CreateTestChart = new RateCharts();
            //CreateTestChart.CreateChart();
        }
    }




    public class RateCharts
    {


        public RateCharts()
        {
        }
        public void CreateChart(ref Chart Chart1)
        {


            Chart1.Type = ChartType.Combo;//Horizontal;
            Chart1.Width = 600;
            Chart1.Height = 350;
            Chart1.TempDirectory = "temp";

            // Rate charts can be used to show many interesting stats. For this sample we will make a chart that will show
            // click through rates for banner campaigns.

            // Lets get our data first. The methods below will generate some random data for us to use.

            Series views = RateCharts.getRandomViewsData();
            Series clicks = RateCharts.getRandomClicksData();

            // Now to get a rate is as easy as this:
            Series rate = clicks / views;

            // We need a new name for the series
            rate.Name = "CTR";


            // If we want to show the clicks, views, and rates then we need to create a new y axis because the CTR is so 
            // small that it will not be readable.
            Axis ctrAxis = new Axis("Click Through Ratio (CTR)");

            // A new number precision has be to supplied so the numbers can be seen. Otherwise we will see only 0s on the axis.
            ctrAxis.NumberPrecision = 4;
            // Lets move it on the right side also 
            ctrAxis.Orientation = dotnetCHARTING.WinForms.Orientation.Right;

            // Now to assign the ctr axis to the ctr series:
            rate.YAxis = ctrAxis;


            // In the legend the values are sums by default and that does not make sense for CTR so lets 
            // make the value in the legend an average for the ctr series.
            rate.LegendEntry.Value = "Average: %YAverage";


            // Show values on bars
            Chart1.DefaultSeries.DefaultElement.ShowValue = true;


            // Add the data.
            Chart1.SeriesCollection.Add(views);
            Chart1.SeriesCollection.Add(clicks);
            Chart1.SeriesCollection.Add(rate);

        }

        static Series getRandomViewsData() // This method will generate a series representing views for our banners
        {

            Random myR = new Random(1);

            Series s = new Series();
            s.Name = "Views";
            for (int b = 1; b < 5; b++)
            {
                Element e = new Element();
                e.Name = "Banner " + b; ;
                e.YValue = 50 + myR.Next(500);
                s.Elements.Add(e);
            }


            return s;
        }

        static Series getRandomClicksData() // This method will generate a series representing clicks for our banners
        {

            Random myR = new Random(2);

            Series s = new Series();
            s.Name = "Clicks";
            for (int b = 1; b < 5; b++)
            {
                Element e = new Element();
                e.Name = "Banner " + b; ;
                e.YValue = myR.Next(50);
                s.Elements.Add(e);
            }


            return s;
        }
    }
}

See you are using types from a dotnetCHARTING namespace, do know how these work via some sort of documentation?
I don't see some kind of ShowtheGraph method in here.

You will need to call CreateChart() using a Chart object as an argument I presume that there is a Chart described in dotnetCHARTING.WinForms that you will need to use.

I don't know what a Chart is so I can't be sure but I suspect you need to do somthing like this:

private void button1_Click(object sender, EventArgs e)        
{
    Chart myChart = new Chart();

    RateCharts CreateTestChart = new RateCharts();            
    CreateTestChart.CreateChart(ref myChart);        
}
This article has been dead for over six months. Start a new discussion instead.