Profile Picture

How to add multiple bars each with a column of datatable data

Posted By Hamza Ahmad 11 Years Ago

How to add multiple bars each with a column of datatable data

Author
Message
Hamza Ahmad
explanationmark Posted 11 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: 11 Years Ago
Posts: 1, Visits: 1
Hello

I just downloaded the trial version of the software and just needed some help with a couple of basic questions. I have tried searching for the answers in the knowledge base and the online documentation but couldn't anything specific to my problem.

I am trying to create a basic bar chart which will have data from a datatable containing 4 columns. The datatable (dt1) looks like this.

Year ReconciledDepreciation ResearchAndDevelopment EBITDA
2006 207513626.612477 58247975.7894737 824654651.915216
2007 236220990.948262 75966059.625 772393859.003076
2008 284162855.692862 74992057.7313702 635706072.900386
2009 264901898.736738 65072308.6726563 246755262.461744
2010 270855777.661023 71033591.5718994 490107131.512199
2011 284140863.384655 75284635.8967014 626125011.048656
2012 338216976.017724 86471749.9354839 561443637.887348


What I want essentially is to have the years column represented on x-axis and the rest of the columns represented as individual bars on the chart.


I have tried using the following code which I found in the online documentation to get multiple columns data from a datatable:

Dim arrSeries As NDataSeriesCollection = bar.GetDataSeries(DataSeriesMask.Values Or DataSeriesMask.Labels, DataSeriesMask.None, False)

Dim arrCollumns As String() = {"ReconciledDepreciation", "ResearchAndDevelopment"}

arrSeries.FillFromDataTable(dt1, arrCollumns)

But it only takes up to two columns(I need to input three) and also displays bars as combination of the two columns of data, not individual columns as a bar. See img1

Secondly I want the years to be on the x-axis not on the y axis like they are right now. See img2

I saw in the knowledge base that one way to add labels to x-axis is using the following code

Dim scale As NStandardScaleConfigurator = DirectCast(chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator, NStandardScaleConfigurator)
scale.AutoLabels = False
scale.Labels.Add("2006")
scale.Labels.Add("2007")
scale.Labels.Add("2008")
....

But is there a more dynamic way to do it i.e just give the column name containing the years ? because i have other datatables with a lot more x-axis values and it is not feasible to add each x-axis label by yourself.



Thank you

Hamza


Attachments
img1.png (160 views, 155.00 KB)
img2.png (137 views, 156.00 KB)
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 Hamza,

1. Regarding the bars – you have to manually create three Bar series and fill each one from the respective DataTable column. The easiest way to import data into a single data series is using the FillFromDataTable method, for example:

NBarSeries barSeries0 = new NBarSeries();
barSeries0.Values.FillFromDataTable(dataTable, “ReconciledDepreciation”);

The attached example does this in a loop for the three series.

2. Regarding the axis labels – you need to import the category names and feed them to the axis via code – for example:

NOrdinalScaleConfigurator scaleX = (NOrdinalScaleConfigurator)chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator;
scaleX.AutoLabels = false;

for (int i = 0; i < dt.Rows.Count; i++)
{
                scaleX.CustomLabels.Add(new NCustomValueLabel(i, dt.Rows[i][0].ToString()));
}

Hopefully this helps – let us know if you meet any problems or have any questions.



Best Regards,
Nevron Support Team



Attachments
WinFormsApp.zip (115 views, 11.00 KB)


Similar Topics


Reading This Topic