MsChart Axis X Minimum value being overridden to a lower value - asp.net

I have been trying to solve this issue from some time now. The symptom is with the X axis I see that the value get overrided to a lower value from what I have set it at in Chart1.ChartAreas(0).AxisX.Minimum = Xmin (8.5 in this case) . However when I times the values by 100 the curve seems to center to a min and max. I am also not experiencing this with the Y axis at all. In the picture attached I am setting the min to 8.5 ( as seen where the curve starts in the picture. I also notice if I set the min below 8 it will let me set it to that. So this leads me to believe there is some sort of value that its overriding ratio to make the minimum inside of MSchart.
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.IO
Imports System.Drawing
Public Class Test
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim value As Double
Dim xxmax As Double
Dim yymax As Double
Dim xxmin As Double
Dim yymin As Double
Dim XPlot As New ArrayList
Dim YPlot As New ArrayList
XPlot.Add(10.1)
XPlot.Add(10.15)
XPlot.Add(10.2)
XPlot.Add(10.25)
XPlot.Add(10.3)
YPlot.Add(1)
YPlot.Add(2)
YPlot.Add(3)
YPlot.Add(4)
YPlot.Add(5)
xxmin = 10.1
xxmax = 10.3
yymin = 1
yymax = 5
Chart1.Series.Clear()
Chart1.Series.Add("Polfit Fit")
Chart1.Series("Polfit Fit").XValueType = System.Web.UI.DataVisualization.Charting.ChartValueType.Int32
Chart1.Series("Polfit Fit").ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line
Chart1.Series.Add("Plotted Data")
Chart1.Series("Plotted Data").XValueType = System.Web.UI.DataVisualization.Charting.ChartValueType.Int32
Chart1.Series("Plotted Data").ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Point
Chart1.Series("Plotted Data").MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Circle
Chart1.Series("Plotted Data").MarkerSize = 10
Chart1.Series("Plotted Data").MarkerColor = Color.Green
Chart1.Series("Polfit Fit").Color = Color.Blue
Dim mylegend As New System.Web.UI.DataVisualization.Charting.Legend
mylegend.Font = New System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Bold)
mylegend.Name = "Legend"
mylegend.BorderWidth = 4
mylegend.BorderColor = Color.Black
mylegend.Docking = DataVisualization.Charting.Docking.Right
Chart1.Legends.Add(mylegend)
Chart1.ChartAreas(0).AxisX.Title = Value
Chart1.ChartAreas(0).AxisX.TitleFont = New System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Bold)
Chart1.ChartAreas(0).AxisY.TitleFont = New System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Bold)
Chart1.ChartAreas(0).AxisY.Title = "Margin Of Safety"
Chart1.ChartAreas(0).AxisX.IsMarginVisible = True
Chart1.ChartAreas(0).AxisY.IsMarginVisible = True
Chart1.ChartAreas(0).AxisY.IsStartedFromZero = False
Chart1.ChartAreas(0).AxisX.IsStartedFromZero = False
Chart1.ChartAreas(0).AxisX.Interval = 0.05
Chart1.ChartAreas(0).AxisY.Interval = 0.05
Chart1.ChartAreas(0).AxisX.Maximum = Math.Round((xxmax + Math.Abs(xxmax * 0.0)), 6)
Chart1.ChartAreas(0).AxisX.Minimum = Math.Round((xxmin - Math.Abs(xxmax * 0.0)), 6)
Chart1.ChartAreas(0).AxisY.Maximum = Math.Round((yymax + Math.Abs(yymax * 0.0)), 6)
Chart1.ChartAreas(0).AxisY.Minimum = Math.Round((yymin - Math.Abs(yymin * 0.0)), 6)
Chart1.Height = 600
Chart1.Width = 1500
Dim j
Dim b
While j < XPlot.Count
If Not YPlot(j) = "0" And Not (CDbl(XPlot(j)) / CDbl(YPlot(j)) = 1) Then
Dim point As New System.Web.UI.DataVisualization.Charting.DataPoint
point.SetValueXY((XPlot(j)), (YPlot(j)))
Chart1.Series("Plotted Data").Points.Add(point)
End If
j += 1
End While
b = 0
End Sub
End Class
<%# Page Language="VB" Inherits ="Test" CodeFile ="Test.vb" %>
<%# Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form runat="server" >
<asp:Chart ID="Chart1" runat="server">
<Series>
<asp:Series Name="Series1">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
</form>
</body>
</html>

Chart1.Series("Plotted Data").XValueType = System.Web.UI.DataVisualization.Charting.ChartValueType.Int32
should be
Chart1.Series("Plotted Data").XValueType = System.Web.UI.DataVisualization.Charting.ChartValueType.Double
That is what was causing the problem. Thank you Babback that solves the issue.

Related

Trouble Returning List of string of all looped xml elements in function

I am trying to make this function return a (list/multidarray) of the 7 BranchHours.childnodes for this branchID that I can call with a little code in my codebehind page.
here is what one section of the xmlfile looks like (BranchesInfo)
<BranchInfo>
<BranchId>db</BranchId>
<Name></Name>
<ShortName></ShortName>
<ImageUrl></ImageUrl>
<BranchHours>
<Hours>
<DayOfWeek>Sunday</DayOfWeek>
<Open>12:00</Open>
<Close>5:00</Close>
</Hours>
<Hours>
<DayOfWeek>Monday</DayOfWeek>
<Open>10:00</Open>
<Close>8:00</Close>
</Hours>
<Hours>
<DayOfWeek>Tuesday</DayOfWeek>
<Open>10:00</Open>
<Close>8:00</Close>
</Hours>
<Hours>
<DayOfWeek>Wednesday</DayOfWeek>
<Open>10:00</Open>
<Close>8:00</Close>
</Hours>
<Hours>
<DayOfWeek>Thursday</DayOfWeek>
<Open>10:00</Open>
<Close>6:00</Close>
</Hours>
<Hours>
<DayOfWeek>Friday</DayOfWeek>
<Open>10:00</Open>
<Close>6:00</Close>
</Hours>
<Hours>
<DayOfWeek>Saturday</DayOfWeek>
<Open>12:00</Open>
<Close>5:00</Close>
</Hours>
</BranchHours>
</BranchInfo>
code
'app_code function below
Public Shared Function MyFunc(ByVal branchCode As String) As List(Of String)
Dim URLString As String = "url/branchesTesting.xml"
Dim xmlDoc As XDocument = XDocument.Parse(URLString)
XDocument.Load(URLString)
Dim labelMan As List(Of String)
Dim x As Integer = (0) 'looping variable
' Dim i As Integer = 1
Dim branchid = xmlDoc.XPathSelectElements("/BranchesInfo/BranchInfo[BranchId='" & branchCode & "']/BranchHours/Hours")
'Dim varList As New List(Of String)
Dim Items = From BranchHours In xmlDoc.XPathSelectElements("/BranchesInfo/BranchInfo[BranchId='" & branchCode & "']/BranchHours/Hours") _
Select DayOfWeek = (BranchHours.Elements("DayOfWeek").Value),
Open = (BranchHours.Elements("Open").Value), _
Close = (BranchHours.Elements("Close").Value)
' Dim lists = xmlDoc.Root.Elements("BranchHours").[Select](Function(element) element.Value).ToList()
For Each Hours In Items
' For i As Integer = 0 To Items.Count - 1
' lists = labelMan
labelMan = "<div>DayOfWeek:" & Hours.DayOfWeek & "Open:" & Hours.Open & "Close: " & Hours.Close & "</div>" ' ----- error Error 34 Value of type 'String' cannot be converted to 'System.Collections.Generic.List(Of String)'.
' Else
' i += 1
' End If
labelMan = labelMan
'Next
Next
' If labelMan = "" Then
'labelMan = "No Results."
'End If
Return labelMan
End Fuction
Public Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Call BranchHours.branchHours.MyFunc("dr")
Label1.Text = BranchHours.branchHours.MyFunc("dr") ' ----- Error Error 35 Value of type 'System.Collections.Generic.List(Of String)' cannot be converted to 'String'.
End Sub
Ideal Results
Day of the Week Open Close
(0)Sunday 12:00 5:00
(1)Monday 10:00 8:00
(2)Tuesday 10:00 8:00
(3)Wednesday 10:00 8:00
(4)Thursday 10:00 6:00
(5)Friday 10:00 6:00
(6)Saturday 10:00 5:00
--- the (i) would not be visible its for referencing the results in the future.
please let me know if you need any additional information. Thank you!
First you need to instantiate your List(of String). Right now for you it is Nothing.
Dim labelMan As List(Of String) = New List(of String)
Then you need to use the List(of T) Add method:
labelMan.Add("<div>DayOfWeek:" & Hours.DayOfWeek & "Open:" & Hours.Open & "Close: " & Hours.Close & "</div>")
Thanks Again to those who helped me. Here the complete answer w/ comments:)
side note -- This code will be audited, so for those who can see places that I should add testing or should make improvement in the code below. Please feel free to advise/comment.
App_Code Function >
Namespace BranchHours
Public Class branchHours
'function will accecpt string of branch ID and return value to be a List(of string)
Public Shared Function MyFunc(ByVal branchCode As String) As List(Of String)
'set XML URL path
Dim URLString As String = "url/branchesTesting.xml"
'load URL Path
Dim xmlDoc As XDocument = XDocument.Load(URLString)
' instantiate List(of String)
Dim labelMan As List(Of String) = New List(Of String)
'define items start path in xml document based on passsed branchcode id
'select and set xml element variable and return value/innertext for branch hours
Dim Items = From BranchHours In xmlDoc.XPathSelectElements("/BranchesInfo/BranchInfo[BranchId='" & branchCode & "']/BranchHours/Hours") _
Select DayOfWeek = (BranchHours.Elements("DayOfWeek").Value),
Open = (BranchHours.Elements("Open").Value), _
Close = (BranchHours.Elements("Close").Value) _
'BranchID = (branchname.Elements("BranchId").Value)
For Each Hours In Items
' use the List(of T) Add method: to add each hours' nodes to list, you can also add some html tags here if you to style it a bit more then plain text
labelMan.Add(Hours.DayOfWeek & "," & Hours.Open & "," & Hours.Close)
Next
Return labelMan
End Function
End Class
End Namespace
Code Behind >
Public Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
' this line will call one of the specified list items
Label2.Text = BranchHours.branchHours.MyFunc("dr").ElementAt(1)
Call BranchHours.branchHours.MyFunc("dr")
'This block below will return the full list of branchhours
Dim i As Integer = 0
Dim rangex As List(Of String) = BranchHours.branchHours.MyFunc("dr")
Dim message = String.Join(Environment.NewLine, rangex.ToList())
For Each Items As String In rangex
' Do something with items
Label1.Text = message
'Next
End Sub
Front .aspx
<%# Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="Default3bh.aspx.vb" Inherits="Default3bh" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:Label ID="Label1" runat="server" ></asp:Label>
<asp:Label ID="Label2" runat="server" ></asp:Label>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="AdditionalContent" Runat="Server">
</asp:Content>
Results >
Label2 : Monday,10:00,6:00
label1 : Sunday,Closed,Closed Monday,10:00,6:00 Tuesday,10:00,8:00 Wednesday,10:00,6:00 Thursday,10:00,6:00 Friday,10:00,6:00 Saturday,10:00,5:00

Change cell in datagridview with databindings of SQL Server stored procedure

In SQL Server, I created a dynamic SQL stored procedure to query for the production record and pivoted in each month
In ASP.net using VB.net, I have a page with a DataGrid to display the query results dynamically using the DataBound method
I have a textbox to change the value of specific cell in the DataGridView like the production order quantity
Problem: when I assigned a value from textbox to the cell of datagridview, there is no change at all.
It just refreshed and get the value of the SQL query from the stored procedure. It always invokes the DataBound method of the DataGrid.
Questions: what is the technique so that I can assign the value to cell of DataGridView which is has data binding to the dynamic SQL Server stored procedure? The thing here is I want to save the changes in the DataGrid to another Table as the transnational.
Here is aspx code:
<%# Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="GeneratePlan.aspx.vb" Inherits="GeneratePlan" %>
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.style1
{
width: 55px;
}
.style2
{
width: 7px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<div>
<table width="100%">
<tr >
<td style="text-align: right;" >
<asp:Button ID="btnSave" runat="server" Text="Save Plan" CssClass="button" /><asp:Button ID="btnExit" runat="server" Text="Exit" CssClass="button" />
</td>
</tr>
<tr>
<td class="tdHeaderSubSection">
<asp:Label ID="lblReq" runat="server" Text=">> Generate Plan"></asp:Label>
</td>
</tr>
</table>
</div>
<div>
<table width ="100%">
<tr>
<td class="style1">
<asp:Label ID="Label3" runat="server" Text="BU"></asp:Label></td>
<td class="style2">::</td>
<td>
<asp:DropDownList ID="ddlBU" CssClass="Data" runat="server" Height="16px"
Width="130px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td></td>
<td></td>
<td>
<asp:Button ID="btnGenerate" CssClass="button" runat="server" Text="Generate" />
<asp:Button ID="btnMove" CssClass="button" runat="server"
Text="Move MC#" />
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td colspan ="3"> <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager> </td>
</tr>
</table>
</div>
<div id ="planDtl">
<asp:GridView ID="grdPlanDtl" AutoGenerateColumns = "False"
runat="server" Font-Size="10px">
</asp:GridView>
</div>
<div>
</div>
</asp:Content>
Here is the vb.net code:
Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles grdPlanDtl.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ItemCode As New Label()
ItemCode.ID = "ItemCode"
ItemCode.Text = TryCast(e.Row.DataItem, DataRowView).Row("ItemCode").ToString()
e.Row.Cells(1).Controls.Add(ItemCode)
ItemCode.Width = 100
Dim Description As New Label()
Description.ID = "Description"
Description.Text = TryCast(e.Row.DataItem, DataRowView).Row("Description").ToString()
e.Row.Cells(2).Controls.Add(Description)
Description.Width = 200
Dim WH As New Label()
WH.ID = "WH"
WH.Text = TryCast(e.Row.DataItem, DataRowView).Row("WH").ToString()
e.Row.Cells(3).Controls.Add(WH)
e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Center
WH.Width = 10
Dim Customer As New Label()
Customer.ID = "Customer"
Customer.Text = TryCast(e.Row.DataItem, DataRowView).Row("CustName").ToString()
e.Row.Cells(4).Controls.Add(Customer)
Customer.Width = 150
Dim ST As New Label()
ST.ID = "ST"
ST.Text = FormatNumber(TryCast(e.Row.DataItem, DataRowView).Row("Std.Time").ToString(), 2)
e.Row.Cells(5).Controls.Add(ST)
e.Row.Cells(5).HorizontalAlign = HorizontalAlign.Right
ST.Width = 30
Dim TON As New Label()
TON.ID = "TON"
TON.Text = TryCast(e.Row.DataItem, DataRowView).Row("Tonnage").ToString()
e.Row.Cells(6).Controls.Add(TON)
e.Row.Cells(6).HorizontalAlign = HorizontalAlign.Right
TON.Width = 40
Dim MachineNo As New Label()
MachineNo.ID = "MachineNo"
MachineNo.Text = TryCast(e.Row.DataItem, DataRowView).Row("MachineNo").ToString()
e.Row.Cells(7).Controls.Add(MachineNo)
MachineNo.Width = 50
Dim TRP As New Label()
TRP.ID = "TRP"
TRP.Text = TryCast(e.Row.DataItem, DataRowView).Row("TRP").ToString()
e.Row.Cells(10).Controls.Add(TRP)
TRP.Width = 50
Dim FixedMachine As New Label()
Dim strFix As String
FixedMachine.ID = "FixedMachine"
FixedMachine.Text = TryCast(e.Row.DataItem, DataRowView).Row("FixedMachine").ToString()
e.Row.Cells(8).Controls.Add(FixedMachine)
FixedMachine.Width = 50
Dim chkSel As New CheckBox
chkSel.ID = "Move"
chkSel.Checked = False
e.Row.Cells(0).Controls.Add(chkSel)
Dim row As GridViewRow = TryCast(FixedMachine.NamingContainer, GridViewRow)
strFix = TryCast(row.FindControl("FixedMachine"), Label).Text
If String.IsNullOrEmpty(strFix) Then
chkSel.Enabled = True
Else
chkSel.Enabled = True
' chkSel.Enabled = False
End If
' AddGrdColumn("AvailableTime", "Available Time", "Lable")
'getsum
strGrpMC = TON.Text & MachineNo.Text
For i As Integer = 0 To iLoopMonth - 1
Dim ShpOrd As New Label()
Dim ShpOrdBckOrd As New TextBox()
Dim PlanM1 As New TextBox()
Dim ActualM1 As New TextBox()
Dim BackOrder As New Label()
Dim NeedHr As New Label()
ShpOrd.ID = "ShpOrd"
ShpOrd.Text = TryCast(e.Row.DataItem, DataRowView).Row(arrayMonth(i)).ToString()
e.Row.Cells(11 + (9 * i) + i).Controls.Add(ShpOrd)
ShpOrd.Width = 50
ShpOrdBckOrd.ID = "ShpOrdBckOrd"
ShpOrdBckOrd.Text = ShpOrd.Text
e.Row.Cells(12 + (9 * i) + i).Controls.Add(ShpOrdBckOrd)
ShpOrdBckOrd.Width = 50
PlanM1.ID = "PlanM1"
PlanM1.Text = ""
e.Row.Cells(13 + (9 * i) + i).Controls.Add(PlanM1)
PlanM1.Width = 50
ActualM1.ID = "ActualM1"
ActualM1.Text = ""
ActualM1.AutoPostBack = True
AddHandler ActualM1.TextChanged, AddressOf txtAcutal_TextChanged
e.Row.Cells(14 + (9 * i) + i).Controls.Add(ActualM1)
ActualM1.Width = 50
BackOrder.ID = "BackOrder"
BackOrder.Text = ""
BackOrder.Text = GetBackOrder(ShpOrdBckOrd.Text, ActualM1.Text)
e.Row.Cells(15 + (9 * i) + i).Controls.Add(BackOrder)
BackOrder.Width = 50
NeedHr.ID = "NeedHr"
NeedHr.Text = GetNeedHr(ShpOrd.Text, PlanM1.Text, ST.Text, TRP.Text)
e.Row.Cells(16 + (9 * i) + i).Controls.Add(NeedHr)
NeedHr.Width = 50
' summary
' MsgBox("strGrpMC : " & strGrpMC)
' MsgBox("strTmpGrpMC : " & strTmpGrpMC)
strGrpMC = TON.Text & "-" & MachineNo.Text
If strGrpMC <> strTmpGrpMC Then
LodTmeTT = 0
BalTmeTT = 0
strTmpGrpMC = strGrpMC
strGrpMC = TON.Text & "-" & MachineNo.Text
LodTmeTT = LodTmeTT + Convert.ToDouble(ChkNull(GetNeedHr(ShpOrd.Text, PlanM1.Text, ST.Text, TRP.Text), 0))
Else
strTmpGrpMC = strGrpMC
strGrpMC = TON.Text & "-" & MachineNo.Text
LodTmeTT = LodTmeTT + Convert.ToDouble(ChkNull(GetNeedHr(ShpOrd.Text, PlanM1.Text, ST.Text, TRP.Text), 0))
End If
'("#,##0.00")
Dim AvailableTime As New TextBox()
AvailableTime.ID = "AvailableTime"
AvailableTime.Text = TryCast(e.Row.DataItem, DataRowView).Row("AvailableTime").ToString()
e.Row.Cells(18 + (9 * i) + i).Controls.Add(AvailableTime)
AvailableTime.Width = 50
Dim Loading As New Label()
Loading.ID = "Loading"
Loading.Text = LodTmeTT
e.Row.Cells(17 + (9 * i) + i).Controls.Add(Loading)
Loading.Width = 50
Loading.Text = LodTmeTT
Dim balTme As New Label()
balTme.ID = "balTme"
balTme.Text = GetBalTime(AvailableTime.Text, Loading.Text)
e.Row.Cells(19 + (9 * i) + i).Controls.Add(balTme)
balTme.Width = 50
Dim RatioTme As New Label()
RatioTme.ID = "RatioTme"
RatioTme.Text = GetLoadRatioTime(Loading.Text, AvailableTime.Text)
e.Row.Cells(20 + (9 * i) + i).Controls.Add(RatioTme)
RatioTme.Width = 50
Next
End If
End Sub

Two graphics and the same chart

I want to add a spline graphic and a points graphic on the same asp.net chart. Can somebody show an explicite example of how you do that?
Thank you.
Would be nice to know if you want a C# or a Visual Basic example. I've got a Visual Basic one for you. (You could convert it to C# with an online converter). I hope this helps you.
.aspx file:
<form id="form1" runat="server">
<div>
<asp:Chart ID="Chart1" runat="server">
<ChartAreas>
<asp:ChartArea Name="ChartArea1"></asp:ChartArea>
</ChartAreas>
</asp:Chart>
</div>
</form>
.vb file:
Imports System.Web.UI.DataVisualization.Charting
Imports System.Drawing
Public Class ChartExample
Inherits System.Web.UI.Page
Private Sub Page_load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Add the title
Chart1.Titles.Add("Title1")
' Set the text of the title
Chart1.Titles("Title1").Text = "Chart Area 1 Title"
' Dock the title to a ChartArea
Chart1.Titles("Title1").DockedToChartArea = "ChartArea1"
' Creating the series
Dim series1 As New Series("Series1")
Dim series2 As New Series("Series2")
' Setting the Chart Type
series1.ChartType = SeriesChartType.Spline
series2.ChartType = SeriesChartType.Point
' Adding some points
series1.Points.AddXY(0, 10)
series1.Points.AddXY(5, 16)
series1.Points.AddXY(10, 9)
series1.Points.AddXY(15, 32)
series1.Points.AddXY(20, 21)
series2.Points.AddXY(0, 5)
series2.Points.AddXY(5, 12)
series2.Points.AddXY(10, 18)
series2.Points.AddXY(15, 11)
series2.Points.AddXY(20, 25)
' Add the series to the chart
Chart1.Series.Add(series1)
Chart1.Series.Add(series2)
' Set the chart's height and width
Chart1.Width = 600
Chart1.Height = 600
' Setting the X Axis
Chart1.ChartAreas("ChartArea1").AxisX.IsMarginVisible = True
Chart1.ChartAreas("ChartArea1").AxisX.Interval = 1
Chart1.ChartAreas("ChartArea1").AxisX.Maximum = [Double].NaN
Chart1.ChartAreas("ChartArea1").AxisX.Title = "x"
Chart1.ChartAreas("ChartArea1").AxisX.TitleFont = New Font("Sans Serif", 10, FontStyle.Bold)
' Setting the Y Axis
Chart1.ChartAreas("ChartArea1").AxisY.Interval = 2
Chart1.ChartAreas("ChartArea1").AxisY.Maximum = [Double].NaN
Chart1.ChartAreas("ChartArea1").AxisY.Title = "y"
Chart1.ChartAreas("ChartArea1").AxisY.TitleFont = New Font("Sans Serif", 10, FontStyle.Bold)
End Sub
End Class

Get filenotfoundexception using RadAsyncUpload

i use the Telerik radasyncupload control like this:
Web.Config
<appSettings>
<add key="Telerik.AsyncUpload.TemporaryFolder" value="~/App_Data/RadUploadTemp" />
</appSettings>
ASP.NET
<telerik:RadAsyncUpload ID="rauIconUpload" runat="server" ChunkSize="0" Localization-Cancel="Löschen" Localization-Remove="Entfernen" Localization-Select="Auswählen"
Culture="de-DE" Skin="MetroTouch" TargetFolder="img/icons" MaxFileInputsCount="1">
</telerik:RadAsyncUpload>
<telerik:RadButton ID="rbtnIconUpload" runat="server" Text="Speichern" Skin="MetroTouch"></telerik:RadButton>
VB.NET
Private Sub rbtnIconUpload_Click(sender As Object, e As EventArgs) Handles rbtnIconUpload.Click
If rtxtIconBezeichnung.Text = String.Empty Or rtxtIconBezeichnung.Text = Nothing Or CHKValidation(rtxtIconBezeichnung.Text) = False Then
rnfUngueltigeEingabe.Visible = True
Else
Try
For Each f As UploadedFile In rauIconUpload.UploadedFiles
Dim img As New System.Drawing.Bitmap(f.InputStream)
Dim h As Integer = img.Height
Dim w As Integer = img.Width
img.Dispose()
Dim fileName As String = f.GetName()
IconPfad = "~/img/icons/" & fileName
If w = 16 And h = 16 Then
IconSize = "16x16"
ElseIf w = 32 And h = 32 Then
IconSize = "32x32"
Else
rnfIconNichtErzeugt.Visible = True
Exit For
End If
IconErzeugt = Datenzugriff.CRTNeuesIcon(rtxtIconBezeichnung.Text, IconPfad, rcbIconGruppe.SelectedValue, IconSize)
If IconErzeugt = True Then
rnfIconErzeugt.Visible = True
Page.ClientScript.RegisterClientScriptBlock([GetType](), "CloseScript", "redirectParentPage('IconVerwaltung.aspx')", True)
Else
rnfIconNichtErzeugt.Visible = True
End If
Next
Catch ex As Exception
rnfIconNichtErzeugt.Visible = True
End Try
End If
End Sub
If i try to use InputStream i get a filenotfoundexeption. I added a Screanshot of this error.
So, does someone have a idea what i'm doing wrong?
Thank you for reading.
Daniel
Try to remove the TargetFolder property from the markup:
<telerik:RadAsyncUpload ID="rauIconUpload" runat="server" ChunkSize="0" Localization-Cancel="Löschen" Localization-Remove="Entfernen" Localization-Select="Auswählen"
Culture="de-DE" Skin="MetroTouch" MaxFileInputsCount="1">
</telerik:RadAsyncUpload>
and save the file manually from in the click button event.

Position values are not match with actual values

Microsoft Chart Control generates a different visual then the set property. Property based it always shows correct value but if you open the generated chart with graphic software like Photoshop it shows pixels are not matching with the set property.
I found this bug while trying to retrieve all InnerPlot Positions into a HiddenField. Based on this bug right now, there is no way to get correct absolute position of ChartAreas or InnerPlots. Please let me know if you believe there is a workaround about it...
Thank you for your time and attention...
STEPS TO REPRODUCE
Test.aspx
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="Test" %>
<%# Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Chart ID="Chart1" runat="server"></asp:Chart>
</div>
</form>
</body>
</html>
Test.aspx.vb
Imports System.Web.UI.DataVisualization.Charting
Partial Class Test
Inherits System.Web.UI.Page
Private Sub DataHelper()
Dim Historical() As String = _
{ _
"Date,Open,High,Low,Close,Volume", _
"2009-03-05,1.75,2.00,1.73,1.81,47339300", _
"2009-03-04,1.90,1.90,1.83,1.87,22306600", _
"2009-03-03,1.91,1.91,1.80,1.81,15412400", _
"2009-03-02,1.91,1.94,1.83,1.88,19585500", _
"2009-02-27,1.93,2.00,1.80,2.00,31469500", _
"2009-02-26,2.08,2.09,1.81,1.98,32307100", _
"2009-02-25,2.10,2.16,2.00,2.01,54325200", _
"2009-02-24,1.80,2.00,1.80,2.00,33935300", _
"2009-02-23,1.65,1.91,1.61,1.73,44444100", _
"2009-02-20,1.60,1.61,1.50,1.58,37889100" _
}
Dim Query As IEnumerable = From HistoricalLine In Historical Skip 1 _
Where Not String.IsNullOrEmpty(HistoricalLine) _
Let HistoricalFields = HistoricalLine.Split(",") _
Let HistoricalDate = CDate(HistoricalFields(0)) _
Order By HistoricalDate Ascending _
Select New With { _
.Date = HistoricalDate, _
.Open = CDbl(HistoricalFields(1)), _
.High = CDbl(HistoricalFields(2)), _
.Low = CDbl(HistoricalFields(3)), _
.Close = CDbl(HistoricalFields(4)), _
.Volume = CDbl(HistoricalFields(5)) _
}
Chart1.DataSource = Query
End Sub
Private Sub CreateChartArea(ByVal areaname As String)
Chart1.ChartAreas.Add(New ChartArea)
With Chart1.ChartAreas.Last
.Name = areaname
.AxisY2.Enabled = AxisEnabled.False
.AxisX2.Enabled = AxisEnabled.False
With .AxisX
.MajorTickMark.Enabled = False
.MinorTickMark.Enabled = False
.MinorGrid.Enabled = False
.MajorGrid.LineColor = Drawing.Color.Yellow
End With
With .AxisY
.MajorTickMark.Enabled = False
.MinorTickMark.Enabled = False
.MinorGrid.Enabled = False
.MajorGrid.LineColor = Drawing.Color.Red
.IsStartedFromZero = False
End With
.BackColor = Drawing.Color.SkyBlue
.BorderDashStyle = ChartDashStyle.Solid
.BorderColor = Drawing.Color.Brown
.BorderWidth = 0
.ShadowOffset = 0
End With
End Sub
Private Sub CreateSeries(ByVal seriename As String, ByVal areaname As String)
Chart1.Series.Add(New Series)
With Chart1.Series.Last
.Name = seriename
.ChartArea = areaname
.YValuesPerPoint = 4
.ChartType = SeriesChartType.Candlestick
.XValueType = ChartValueType.DateTime
.IsXValueIndexed = True
.XValueMember = "Date"
.YValueMembers = "High,Low,Open,Close"
.BorderColor = Drawing.Color.Green
.IsValueShownAsLabel = True
End With
End Sub
Private Sub ChartHelper()
Chart1.ImageStorageMode = ImageStorageMode.UseImageLocation
Chart1.ImageLocation = "~/_temp/HG_#SEQ(300,60)" '<= make sure you have "_temp" directory
Chart1.ImageType = ChartImageType.Png
Chart1.RenderType = RenderType.ImageTag
Chart1.Titles.Add(New Title())
Chart1.Legends.Add(New Legend())
Chart1.Legends.Last.Enabled = False
Chart1.Palette = ChartColorPalette.BrightPastel
Chart1.BackColor = Drawing.Color.Pink
CreateChartArea("A1")
CreateSeries("S1", "A1")
CreateChartArea("A2")
CreateSeries("S2", "A2")
CreateChartArea("A3")
CreateSeries("S3", "A3")
CreateChartArea("A4")
CreateSeries("S4", "A4")
Chart1.DataBind()
Chart1.SaveXml(Server.MapPath("~/_temp/MyChart.xml"))
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
DataHelper()
ChartHelper()
TestPart()
End If
End Sub
Private Sub TestPart()
Dim SpaceBetweenChartAreas As Single = 1 '<= %1 of Chart's Height
Chart1.Height = 500
Chart1.Width = 1000
Dim locator As Integer = 0
For Each chartareaItem In Chart1.ChartAreas
With chartareaItem
.Position.Auto = False
.Position.Height = 20 '500px/100*20 = 100px
.Position.Width = 80 '1000px/100*80 = 800px
.Position.X = 0
.Position.Y = locator
.InnerPlotPosition.Auto = False
.InnerPlotPosition.Height = 100 '%100 of ChartArea Position's Height
.InnerPlotPosition.Width = 100 ' %100 of ChartArea Position's Width
.InnerPlotPosition.X = 0
.InnerPlotPosition.Y = 0
locator += SpaceBetweenChartAreas + .Position.Height
End With
Next
End Sub
End Class
Please don't forget to create a directory "_temp"
Also you can see the actual result at http://ilerler.com/-bug4ms/Test.png
RESULTS
1st ChartArea Height
ACTUAL 101px | EXPECTED 100px
space
ACTUAL 4px | EXPECTED 5px
2nd ChartArea Height
ACTUAL 101px | EXPECTED 100px
space
ACTUAL 4px | EXPECTED 5px
3rd ChartArea Height
ACTUAL 100px | EXPECTED 100px
space
ACTUAL 4px | EXPECTED 5px
4th ChartArea Height
ACTUAL 101px | EXPECTED 100px
space
ACTUAL 85px | EXPECTED 85px
You have the following line:
Dim SpaceBetweenChartAreas As Single = 1 '<= %1 of Chart's Height
That means that your calculations are being performed with single precision float point values - which are highly susceptible to rounding errors.
At the very least you should use Double values.

Resources