Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 923
  • Last Modified:

MS charts data binding in Reverse order

Hi,

I'm using bar charts to represent data from an array for y axis values and for x axis the i'm using an array with hard coded names. I could able to get the chart but the problem is the x axis data and y axis values are not matching.  X axis values are in bottom to top order and y axis values are from top to bottom.

Ex: Suppose i have an array with the following names X, Y and Z for the x- axis and i'm binding the y-axis values as 1.0,2.2,3.3 from the array.
the result i should get is in the order  X -1.0, Y-2.2, Z-3.3. But the result i'm getting is in the order Z-3.3,Y-2.2, X-1.0. There is no problem with the data. I want the order to be in X,Y and Z rather than Z, Y and X.

I tried by giving the x.axis values in reverse order i.e Z, Y and X. But the problem with that is the data is not matching with the correct values. I tried and i couldn't resolve the issue.

Could You please help me to resolve the issue?

Thanks in advance.
0
deepthilomada
Asked:
deepthilomada
  • 5
  • 4
1 Solution
 
BardobraveCommented:
Loop backwards through your data.

Instead of going from 0 to your data array length -1 go from your data array length -1 to 0.
0
 
deepthilomadaAuthor Commented:
Thanks for the information.I would also like to know why my data is getting reversed and is there any property in ms charts that helps to resolve my issue.
0
 
BardobraveCommented:
I haven't used MS Charts before, so I can't tell you if it's related.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
deepthilomadaAuthor Commented:
oh ok. Actually the data into the array comes from a web service.  I'm not using any loop to get the data. so, i'm looking for an property from ms charts which resolves my issue.
0
 
BardobraveCommented:
How do you call your chart? Can you provide us the code you are using to retreive your data and how do you pass it to the chart component? Maybe with that info and with a bit of googling we can give you a solution.

Otherwise you always can invert your data array before passing it to the charts component (although it's not a good option from performance point of view).
0
 
deepthilomadaAuthor Commented:
double[] yValues = { 1.1, 2.5, 7.5, 6.3, 5.2, 4.3};
            string[] xNames = { "Ben", "Marc", "Kim", "Jen", "Kathy", "Bob" };
         
           
            Chart1.Series[0].Points.DataBindXY(xNames,yValues);
MSCharts.png
0
 
BardobraveCommented:
Mmm.... I think that the reason why your data is being loaded this way is because it's being populated across the Y axis from 0 and growing.

This way your first value on the array xNames "Ben" is considered the lesser value and the rest grow from it's point.

Have you tried to show Chart1.Series[0].Points.DataBindXY(yValues, xNames); ?

I think the result would be somewhat more intuitive...
0
 
deepthilomadaAuthor Commented:
That doesn't work out. Thanks for your time. i found a solution. Here is what i did.

 Chart1.ChartAreas[0].AxisX.Minimum = 0;
            Chart1.ChartAreas[0].AxisX.Maximum = 8;
            Chart1.ChartAreas[0].AxisX.IsReversed = true;
0
 
RouchieCommented:
Just to add my two cents worth at the last minute... you should always sort your datasource to the correct order before binding to the chart.  The chart is just a presentational object that will display data exactly how it is given to it.  In your case I would have mapped this data into a DataTable.  It would be very simple and allow the Sort method to be applied on any column

I can give you the simple code for this if you want it?
0
 
deepthilomadaAuthor Commented:
I found a solution.
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now