ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Bar chart in ascending order
Posted by ram on Apr-29-2016 05:22
Hi

I am trying to plot a barchart using data from  two columns and bar graph in ascending order


Column1  Column2

test1 10
test2 30
test3 60
test4 20
test5 40


X-axis values are from Column1 and Y axis value from Column2

I am able to plot the bar graph in ascendng order  but i see the x-axis and y-axis co-ordination is not proper


Eg:



Expecting x axis & y-axis in below order:

test1 10
test4 20
test2 30
test5 40
test3 60

Actual:

test1 10
test2 20
test3 30
test4 40
test5 50

Can you please suggest how to achieve this??

  Re: Bar chart in ascending order
Posted by Peter Kwan on Apr-29-2016 21:31
Hi Ram,

Please sort the rows before passing the data to ChartDirector. If the table is created by an SQL query, you can use ORDER BY to order the rows by column2.

For your case, I think you are sorting only column2 without rearranging column1. This should not be possible in SQL or in a "table". Is it possible your code reads the data into data arrays, and then sort the column2 array without also rearranging the column1 array?

If the above is the cause of the problem, please sort the "rows" using column2 as the key, and not just column2. This will ensure the label is column1 and the value in column2 moves together.

Hope this can help.

Regards
Peter Kwan

  Re: Bar chart in ascending order
Posted by ram on Apr-29-2016 21:49
Thank you Peter.

I cant do this from SQL .

Currently ,Yes I am storing the both column values in array and sorting the column and below is the code I am using it for sorting the column.



column2.sort(function(a, b){return a-b});

var layer = cXY.addBarLayer(column2  ,0X0000FF00);

cXY.xAxis().setLabels(column1).setFontAngle(90);


Jst now tried to sort in before  passing the data to ChartDirector but the same issue exist.



am I making any mistake in sorting the column -column2.sort(function(a, b){return a-b});

  Re: Bar chart in ascending order
Posted by Peter Kwan on Apr-29-2016 23:31
Hi ram,

You should not sort column2. You should sort the "rows" (both column1 and column2) using column2 as the key. Please refer to the Microsoft documentation below:

https://msdn.microsoft.com/en-us/library/2b9cyk6x(v=vs.110).aspx

Hope this can help.

Regards
Peter Kwan