Axis Label linked to Datatable


Author
Message
Ronny Brouillard
Ronny Brouillard
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
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 !
Reply
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K
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


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search