I am trying to work with the HTMLChart negative numbers while setting the Min & Max values on the Y axis. Logic works fine with all dollar/percentages whose values are greater than 0 (zero). The X-axis is all the way in the middle and I have implemented the code suggested here.
Any other suggestions on how I can get the X-axis to remain at the bottom even for negative numbers? I have included the code below
<
telerik:RadScriptBlock
runat
=
"server"
>
<
script
>
function BottomXAxisLabels() {
var chart = $find("<%=RadHtmlChart1.ClientID%>").get_kendoWidget();
var axis = $telerik.$.extend(true, {}, chart.options.categoryAxis);
axis.line.visible = false;
chart.setOptions({ categoryAxis: [{}, axis] });
chart.options.valueAxis.axisCrossingValues = [0, -99999999999];
chart.redraw();
}
function onRequestStart(sender, args) {
if (args.get_eventTarget().indexOf("_btnXLSExport") >= 0) {
args.set_enableAjax(false);
}
}
function OnSeriesClick(args) {
var kendoWidget = args.sender;
alert("You clicked on a series item with value '" + args.value + "' from category '" + args.category + "'.");
}
</
script
>
</
telerik:RadScriptBlock
>
<
telerik:RadHtmlChart
ID
=
"RadHtmlChart1"
runat
=
"server"
Visible
=
"false"
Legend-Appearance-Position
=
"Top"
Width
=
"95%"
>
<
ClientEvents
OnLoad
=
"BottomXAxisLabels"
OnSeriesClick
=
"OnSeriesClick"
/>
<
PlotArea
>
<
Series
>
<
telerik:ScatterLineSeries
DataFieldY
=
"ReturnedValue"
DataFieldX
=
"cycle_Date"
>
<
TooltipsAppearance
Color
=
"White"
>
</
TooltipsAppearance
>
<
LabelsAppearance
Visible
=
"false"
>
</
LabelsAppearance
>
</
telerik:ScatterLineSeries
>
</
Series
>
<
YAxis
>
<
LabelsAppearance
>
<
TextStyle
Bold
=
"true"
/>
</
LabelsAppearance
>
<
MinorGridLines
Visible
=
"false"
></
MinorGridLines
>
<
MajorGridLines
Visible
=
"false"
></
MajorGridLines
>
</
YAxis
>
<
XAxis
DataLabelsField
=
"cycle_Date"
BaseUnit
=
"Years"
MajorTickSize
=
"1"
>
<
LabelsAppearance
Visible
=
"true"
RotationAngle
=
"90"
DataFormatString
=
"Year {0:yyyy}"
>
<
TextStyle
Bold
=
"true"
/>
</
LabelsAppearance
>
<
TitleAppearance
Text
=
"Dates"
>
<
TextStyle
Bold
=
"true"
/>
</
TitleAppearance
>
<
MinorGridLines
Visible
=
"false"
></
MinorGridLines
>
<
MajorGridLines
Visible
=
"true"
></
MajorGridLines
>
</
XAxis
>
</
PlotArea
>
<
ChartTitle
>
<
Appearance
>
<
TextStyle
Bold
=
"true"
/>
</
Appearance
>
</
ChartTitle
>
<
Legend
>
<
Appearance
Visible
=
"true"
Position
=
"Bottom"
></
Appearance
>
</
Legend
>
</
telerik:RadHtmlChart
>
The min value may be something like -0.0545423. I am attempting to create a buffer to the min value and max value.
Private
Sub
grdResults_SelectedIndexChanged(sender
As
Object
, e
As
EventArgs)
Handles
grdResults.SelectedIndexChanged
For
Each
item
As
GridDataItem
In
grdResults.SelectedItems
Dim
strID
As
String
= TryCast(item.FindControl(
"lblRowField"
), Label).Text
Dim
strID2
As
String
= TryCast(item.FindControl(
"lblRowText"
), Label).Text
Dim
strID3
As
String
= TryCast(item.FindControl(
"lblRowNumber"
), Label).Text
Me
.RadHtmlChart1.Visible =
True
GetData(strID, strID2, strID3)
Next
End
Sub
Private
Sub
GetData(InField
As
String
, InColumnName
As
String
, InRowCount
As
String
)
Try
oConn.Open()
Dim
ocmd
As
New
SqlCommand(
"sp_seTrendTracking"
, oConn)
ocmd.CommandType = CommandType.StoredProcedure
With
ocmd.Parameters
.Add(
New
SqlParameter(
"@charter_num"
, Session(
"Charter_Num"
)))
'.Add(New SqlParameter("@charter_num", 95778))
.Add(
New
SqlParameter(
"@field"
, InField))
End
With
reader = ocmd.ExecuteReader
If
reader.HasRows
Then
Dim
dt
As
DataTable =
New
DataTable()
dt.Load(reader)
RadHtmlChart1.DataSource = dt
RadHtmlChart1.ChartTitle.Text = InColumnName
Dim
dr
As
DataRow
dr = dt.Rows(0)
Dim
percentage
As
Double
= 0.1D
'10%
Dim
currentValue
As
Double
If
InRowCount <= 6
Then
RadHtmlChart1.PlotArea.YAxis.LabelsAppearance.DataFormatString =
"{0:c0}"
RadHtmlChart1.PlotArea.CommonTooltipsAppearance.DataFormatString =
"{0:c0}"
'Grab the current value in TextBox1
If
Double
.TryParse(dr(
"Minvalue"
), Globalization.NumberStyles.Number,
Nothing
, currentValue)
Then
'Add 10% of the value to it
currentValue -= dr(
"Minvalue"
) * percentage
RadHtmlChart1.PlotArea.YAxis.MinValue = currentValue.ToString
End
If
If
Double
.TryParse(dr(
"MaxValue"
), Globalization.NumberStyles.Number,
Nothing
, currentValue)
Then
'Add 10% of the value to it
currentValue += dr(
"MaxValue"
) * percentage
RadHtmlChart1.PlotArea.YAxis.MaxValue = currentValue.ToString
End
If
RadHtmlChart1.PlotArea.CommonTooltipsAppearance.DataFormatString =
"{1:c0}<br/>{0:MMM yyyy}"
Else
RadHtmlChart1.PlotArea.YAxis.LabelsAppearance.DataFormatString =
"{0:p2}"
RadHtmlChart1.PlotArea.CommonTooltipsAppearance.DataFormatString =
"{0:p2}"
If
Double
.TryParse(dr(
"Minvalue"
), Globalization.NumberStyles.Number,
Nothing
, currentValue)
Then
Dim
MinValue
As
Decimal
MinValue = dr(
"Minvalue"
)
If
dr(
"MinValue"
) < 0
Then
'percentage = -1.5D
currentValue += MinValue * percentage
Else
'Add 10% of the value to it
currentValue -= dr(
"Minvalue"
) * percentage
End
If
RadHtmlChart1.PlotArea.YAxis.MinValue = currentValue
End
If
If
Double
.TryParse(dr(
"MaxValue"
), Globalization.NumberStyles.Number,
Nothing
, currentValue)
Then
'Add 10% of the value to it
currentValue += dr(
"MaxValue"
) * percentage
RadHtmlChart1.PlotArea.YAxis.MaxValue = currentValue
End
If
RadHtmlChart1.PlotArea.CommonTooltipsAppearance.DataFormatString =
"{1:p2}<br/>{0:MMM yyyy}"
End
If
RadHtmlChart1.DataBind()
End
If
Catch
ex
As
Exception
MyLabel.Text = ex.Message
Finally
oConn.Close()
End
Try
End
Sub