Axis X2 in Chart Director

32 views Asked by At

Good afternoon, guys! I need a little some help with chart director. How I plot a line in Axis Y1 To Axis X2 in vb.net? I've tried a lot, but no success.

I've tried plot line in Y1 to X2.

```

`

If graficoSelecionado = 5 Then

linelayer2.addDataSet(listaUsarEmY.ToArray(), CInt(corEixoY2.ToArgb)).setDataSymbol(Chart.CircleSymbol, 7)

linelayer2.setXData(listaEixoX2.ToArray())

End If`

```

I'm ploting just Y1 To X1

1

There are 1 answers

0
user3100235 On

Assuming the origin of your chart is at (0, 0), the coordinate of a point on the y-axis must be (0, yValue), and a point on the x-axis must be (xValue, 0). So you just need to draw a line with these 2 points:

Dim dataX() As Double = {0, xValue}
Dim dataY() As Double = {yValue, 0}
Dim layer As LineLayer = c.addLineLayer(dataY, myColor)
layer.setXData(dataX)

If you set the origin to some other values, just replace the 0 above with the coordinates of the origin.

If you let ChartDirector to automatically determine the origin, then the above method may not work. It is because ChartDirector will automatically determine the origin based on all of your data values. But in the above code, the data value depends on origin, and this results in circular dependency. In this case, you can try the following method:

.... Draw chart as usual except your y-axis to x-axis line ....

c.layoutAxes()   'Fix the axes based on data available so far

Dim yCoor As Integer = c.getYCoor(yValue)
Dim xCoor As Integer = c.getXCoor(xValue)

c.addLine(c.getPlotArea().getLeftX(), yCoor, xCoor, c.getPlotArea().getBottomY(), myLineColor)

The above assumes the y-axis is on the left side of the plot area, and the x-axis is at the bottom of the plot area.