Profile Picture

Binding Dataset to a Bar Chart

Posted By Simon Turner 13 Years Ago
Author
Message
Simon Turner
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 1, Visits: 1

Hi All

I have been trying to bind a dataset to a bar chart without any success. Does anybody have a simple example for me.

Cheers

Simon



Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hello Simon,

The following example binds the X and Y values of a series to two columns of a data table. Please let us know if you have any questions or comments.


using System;
using System.Data;
using System.Windows.Forms;
using Nevron.Chart;

namespace SimpleDataBinding
{
   public partial class Form1 : Form
   {
      DataSet m_DataSet;

      public Form1()
      {
         InitializeComponent();

         DataTable dataTable = new DataTable("MyTable");
         dataTable.Columns.Add("Position", typeof(double));
         dataTable.Columns.Add("Elevation", typeof(double));
         dataTable.Rows.Add(new object[] { 13, 22 });
         dataTable.Rows.Add(new object[] { 17, 42 });
         dataTable.Rows.Add(new object[] { 21, 14 });
         dataTable.Rows.Add(new object[] { 33, 24 });
         dataTable.Rows.Add(new object[] { 36, 31 });

         m_DataSet = new DataSet("MyDataSet");
         m_DataSet.Tables.Add(dataTable);
      }

      private void Form1_Load(object sender, EventArgs e)
      {
         NChart chart = nChartControl1.Charts[0];
         chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = new NLinearScaleConfigurator();

         NLineSeries series = new NLineSeries();
         series.UseXValues = true;
         chart.Series.Add(series);

         nChartControl1.DataBindingManager.AddBinding(0, 0, "XValues", m_DataSet, "MyTable.Position");
         nChartControl1.DataBindingManager.AddBinding(0, 0, "Values", m_DataSet, "MyTable.Elevation");
      }
   }
}


Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic