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

Message ListMessage List     Post MessagePost Message

  X-Axis and Y-Axis Data Sources
Posted by Karwan Fendi on Apr-06-2009 07:09
HI,

I am using VB2008 express edition. I am facing problems when I read the data for the bar chart and the label for the bar chart from an external source (Array).
I don?t want to specify these data like to be:
Dim Data () as double = {10, 20 ,30}
Dim labels () as string = {?10? , ?20? , ?30? ,?40? , ?50?}

For example: in my code, the source of data for the bar chart is:

Dim data (10) as double
Dim labels (10) as string

For i=1 to 10

Data (i) = i+10   ' Sets values to the data array

Labels (i) = Str$(i)  ' Sets numbers to the labels and convert integers to strings

Next i

When read the data in this, it shrinks the data which don?t correspond to the values on the x-axis. In addition, this make the last value of the data equals to zero!

Tanks in advance for this matter.

Karwan

  Re: X-Axis and Y-Axis Data Sources
Posted by Peter Kwan on Apr-06-2009 16:41
Hi Karwan,

For the last value is 0, it is because there is an error in the code. The "For i = 1 to 10" should be "For i = 0 to 10". It is because the VB array start from the index 0, and ends at the upper bound (10 in your case).

For the "data which don?t correspond to the values on the x-axis", in your current code, I cannot see any value on the x-axis.  (The labels are text strings in your code, not numbers. They are just "names" for human reading, and have no meaning to the program.) So I am not too sure what is the "data which don?t correspond to the values on the x-axis" refer to. Is it possible to include your complete charting code, and also attach an image to help me understand what you get from the code?

Regards
Peter Kwan

  Re: X-Axis and Y-Axis Data Sources
Posted by Karwan Fendi on Apr-06-2009 18:30
Attachments:
HI Peter,

Thank you for your quick response.

This is the code:

Dim Counter As Integer = 0

        Dim data(99) As Double

        Dim labels(99) As String

        For Test = 0 To 6

            data(Test) = Test + 5

            labels(Counter) = Str$(Counter)

            Counter = Counter + 1

        Next

        Dim c As XYChart = New XYChart(400, 400)

        c.setPlotArea(40, 40, 300, 300)

        c.addTitle("MyTittle", "arial bold", 12)
        c.yAxis().setTitle("Y-Axis Tittle")
        c.xAxis().setTitle("X-Axis Tittle")

        c.addLineLayer(data)

        c.xAxis().setLabels(labels)

        WinChartViewer1.Image = c.makeImage()
        c.makeChart("c:/mychart.jpg")


the image is attached. If you need more clarifications, please feel free to ask.


Another question,

If the data are more than the x-axis values (see image 2), how can I relate them to each other? the data are:

X values Y Values
0.1 55
0.3 54
0.5 52
0.7 51
0.9 50
1.1 49
1.3 48
1.5 44
1.7 42
1.9 40
2.1 33
2.3 31
2.5 30
2.7 25
2.9 21

Please note that I've drawn these values in MS Excel.

Many Thanks

Karwan
mychart.jpg
Book1.jpg

  Re: X-Axis and Y-Axis Data Sources
Posted by Peter Kwan on Apr-07-2009 01:32
Hi Karwan,

In your case, you have 100 data points (because you use Dim data(99) As Double), so the chart shows 100 data points.

Your code only sets the first 7 labels. However, this does not mean the remaining 93 elements will disappear. According to standard VB syntax, the remaining values in data must be 0, and the remaining text string must be empty string. (This is a feature of VB, not ChartDirector.)

ChartDirector accurately plot your data, which has 100 points, with 7 non-empty labels, and 93 empty labels.

If you just want to plot In your test code, you should use:

        Dim data(6) As Double
        Dim labels(6) As String

        For Test = 0 To 6
            data(Test) = Test + 5
            labels(Counter) = Str$(Counter)
            Counter = Counter + 1
        Next

Or you may use:

        Dim data(99) As Double
        Dim labels(99) As String

        For Test = 0 To 6
            data(Test) = Test + 5
            labels(Counter) = Str$(Counter)
            Counter = Counter + 1
        Next

        ReDim Preserve data(6)
        ReDim Preserve labels(6)

In general, if you do not want the zero values in the chart and the empty labels on the x-axis, please ensure your data do not include the zero values or the empty labels.

If your data has x-coordinates (not just labels), you may use:

Dim xCoor() As Double
Dim yCoor() As Double
....... fill xCoor and yCoor with your data ......

Dim c As XYChart = New XYChart(400, 400)

c.setPlotArea(40, 40, 300, 300)
c.addTitle("MyTittle", "arial bold", 12)
c.yAxis().setTitle("Y-Axis Tittle")
c.xAxis().setTitle("X-Axis Tittle")

Dim layer As LineLayer = c.addLineLayer(yCoor)
layer.setXData(xCoor)

WinChartViewer1.Image = c.makeImage()
c.makeChart("c:/mychart.jpg")


Hope this can help.

Regards
Peter Kwan

  Re: X-Axis and Y-Axis Data Sources
Posted by Karwan Fendi on Apr-07-2009 16:51
HI again,

That was very helpful! Fantastic indeed!!
Thank you so much!

Karwan - UK