Profile Picture

Axis Label linked to Datatable

Posted By Ronny Brouillard 11 Years Ago
Author
Message
Ronny Brouillard
Posted 11 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 2, Visits: 1
Hi everyone.

I'm trying to make a simple 2D Bar graph linked to a Datatable.

My datas look like this :
NAME - VALUE
OneName - 10
AnotherName - 5
AnotherAgain - 7

I succeded to create the values liked this :

Dim dataBindingManager As NDataBindingManager = chartControl.DataBindingManager
dataBindingManager.AddBinding(0, 0, "Values", MyDataTable, "VALUE")

But I would like to display on the X Axis the NAME field.

Any idea ?

Thanks !

Nevron Support
Posted 11 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: 1 days ago @ 1:54 AM
Posts: 3,054, Visits: 4,009
Hi,

Currently it is not possible to data bind the axis labels, but there is a relatively simple workaround. You can bind the Labels data series of the Bar series and copy the strings to the axis labels (after they are read from the data table). The following example demonstrated this approach:


      void Form1_Load(object sender, EventArgs e)
      {
         dataTable = new DataTable("MyTable");
         dataTable.Columns.Add("Value", typeof(double));
         dataTable.Columns.Add("Name", typeof(string));
         dataTable.Rows.Add(new object[] { 24, "George" });
         dataTable.Rows.Add(new object[] { 19, "Larry" });
         dataTable.Rows.Add(new object[] { 31, "Billy" });
         dataTable.Rows.Add(new object[] { 29, "Stanley" });
         dataTable.Rows.Add(new object[] { 25, "Michael" });

         NChart chart = nChartControl1.Charts[0];
         NBarSeries series = new NBarSeries();
         series.DataLabelStyle.Format = "";
         chart.Series.Add(series);

         nChartControl1.DataBindingManager.AddBinding(0, 0, "Values", dataTable, "Value");
         nChartControl1.DataBindingManager.AddBinding(0, 0, "Labels", dataTable, "Name");

         dataTable.RowChanged += new DataRowChangeEventHandler(dataTable_RowChanged);

         UpdateAxisLabels();
      }

      void dataTable_RowChanged(object sender, DataRowChangeEventArgs e)
      {
         UpdateAxisLabels();
      }

      void UpdateAxisLabels()
      {
         NChart chart = nChartControl1.Charts[0];
         NBarSeries series = (NBarSeries)chart.Series[0];

         NOrdinalScaleConfigurator scaleX = (NOrdinalScaleConfigurator)chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator;
         scaleX.AutoLabels = false;
         scaleX.Labels.Clear();
         scaleX.Labels.AddRange(series.Labels);

         nChartControl1.Refresh();
      }


Best Regards,
Nevron Support Team



Ronny Brouillard
Posted 11 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 2, Visits: 1
Hello, I'm back from holidays with this wonderful answer !
I get the point and used the BindingSource.PositionChanged event to make it work in my case.

Thank you for your support.



Similar Topics


Reading This Topic