Welcome Guest Search | Active Topics |

Server Side Databinding
rogerknuettel
#1 Posted : Friday, May 03, 2013 10:36:01 AM(UTC)
Rank: Newbie

Groups: Registered, WebFormsChart
Joined: 5/3/2013(UTC)
Posts: 5

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hallo,

I´m looking for the possibility to bind the data to the chart on server side code.
Not with a ASP.net control but with a dataview or a dataset.

I didn´t find anything which helps me in the docu.

Is it generally possible?

Greetings
Roger
Ivan
#2 Posted : Friday, May 03, 2013 10:46:59 AM(UTC)
Rank: Administration

Groups: Administrators, Moderator, Registered
Joined: 11/5/2012(UTC)
Posts: 131

Thanks: 0 times
Was thanked: 15 time(s) in 15 post(s)
Hi,

Sure, it is possible. You can download jqChart for ASP.NET Web Forms:

http://www.jqchart.com/Download.aspx

and open the sample under the "samples" folder. It show how to bind jqChart to an ObjectDataSource.

Code:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData"
        TypeName="SamplesBrowser.Models.ChartData"></asp:ObjectDataSource>
    <jqChart:Chart ID="Chart1" Width="500px" Height="300px" runat="server" DataSourceID="ObjectDataSource1">
        <Title Text="Chart Title"></Title>
        <Animation Enabled="True" Duration="00:00:01" />
        <Axes>
            <jqChart:CategoryAxis Location="Bottom" ZoomEnabled="true">
            </jqChart:CategoryAxis>
        </Axes>
        <Series>
            <jqChart:ColumnSeries XValuesField="Label" YValuesField="Value1" Title="Column">
            </jqChart:ColumnSeries>
            <jqChart:LineSeries XValuesField="Label" YValuesField="Value2" Title="Line">
            </jqChart:LineSeries>
        </Series>
    </jqChart:Chart>


With the same way you can bind the chart to a DataView or DataSet. In this case in the XValuesField and YValuesField you need to set the name of the column in your view.
Best,
Ivan Petrov
jqChart Inc.
rogerknuettel
#3 Posted : Friday, May 03, 2013 11:24:05 AM(UTC)
Rank: Newbie

Groups: Registered, WebFormsChart
Joined: 5/3/2013(UTC)
Posts: 5

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hi Ivan,

of course I already loaded this example some weeks ago.
I never ask, before trying to find out a solution on my own ;-)

But a Objectdatasource doesn´t help me. I need a binding to a dataview not to a control.

Anything like:

Chart1.DataSource = ViewChart1
Chart1.DataBind()


Is it possible in this why? And if so, how?
I already tried and don´t get any data to the chart.

Thanks in advance.

Greetings Roger
Ivan
#4 Posted : Friday, May 03, 2013 11:26:41 AM(UTC)
Rank: Administration

Groups: Administrators, Moderator, Registered
Joined: 11/5/2012(UTC)
Posts: 131

Thanks: 0 times
Was thanked: 15 time(s) in 15 post(s)
Is it possible to send us your sample ( support@jqchart.com ), so we can look at it?
Best,
Ivan Petrov
jqChart Inc.
rogerknuettel
#5 Posted : Friday, May 03, 2013 6:38:05 PM(UTC)
Rank: Newbie

Groups: Registered, WebFormsChart
Joined: 5/3/2013(UTC)
Posts: 5

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hallo Ivan,

I´ll tried to send an example, but got a nondelivery message from your mail address.

So I will post parts of my example here:

Server Side Code
Code:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim Table1 As New DataTable("Table")
        Dim Column1Table1 As New DataColumn("Tolerance")
        Table1.Columns.Add(Column1Table1)
        Dim Column2Table1 As New DataColumn("Distribution")
        Table1.Columns.Add(Column2Table1)

        Dim NewRowTable1 As DataRow
        For i As Integer = 0 To 1000
            NewRowTable1 = Table1.NewRow()

            NewRowTable1("Tolerance") = i
            NewRowTable1("Distribution") = Sin(i)
            Table1.Rows.Add(NewRowTable1)

        Next
        Table1.AcceptChanges()

        Dim ViewChart1 As New DataView(Table1)
        Chart2.DataSource = ViewChart1
        Chart2.DataBind()

        Dim ChartLinearAxis As JQChart.Web.UI.WebControls.LinearAxis
        ChartLinearAxis = New JQChart.Web.UI.WebControls.LinearAxis
        ChartLinearAxis.Location = JQChart.Web.UI.WebControls.Location.Bottom
        ChartLinearAxis.ZoomEnabled = True
        Chart2.Axes.Add(ChartLinearAxis)

        Dim Item As JQChart.Web.UI.WebControls.LineSeries
        Item = New JQChart.Web.UI.WebControls.LineSeries
        Item.Title = "MyChart"
        Item.XValuesField = "Tolerance"
        Item.YValuesField = "Distribution"
        Item.LineWidth = 1
        Item.Markers.Visible = False
        Item.StrokeStyle = "#006600"

    End Sub

Greetings
Roger
rogerknuettel
#6 Posted : Tuesday, May 07, 2013 2:16:24 AM(UTC)
Rank: Newbie

Groups: Registered, WebFormsChart
Joined: 5/3/2013(UTC)
Posts: 5

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hallo,

I think it is in everbodies interest, when I post the correct code sample:

Code:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ' define the type of the data column
        Dim typeDouble As System.Type = System.Type.GetType("System.Double")

        Dim Table1 As New DataTable("Table")
        Dim Column1Table1 As New DataColumn("Tolerance", typeDouble)
        Table1.Columns.Add(Column1Table1)
        Dim Column2Table1 As New DataColumn("Distribution", typeDouble)
        Table1.Columns.Add(Column2Table1)

        Dim NewRowTable1 As DataRow
        For i As Integer = 0 To 1000
            NewRowTable1 = Table1.NewRow()

            NewRowTable1("Tolerance") = i
            NewRowTable1("Distribution") = Sin(i)
            Table1.Rows.Add(NewRowTable1)

        Next
        Table1.AcceptChanges()

        Dim ViewChart1 As New DataView(Table1)

        Dim ChartLinearAxis As JQChart.Web.UI.WebControls.LinearAxis
        ChartLinearAxis = New JQChart.Web.UI.WebControls.LinearAxis
        ChartLinearAxis.Location = JQChart.Web.UI.WebControls.Location.Bottom
        ChartLinearAxis.ZoomEnabled = True
        Chart2.Axes.Add(ChartLinearAxis)

        Dim Item As JQChart.Web.UI.WebControls.LineSeries
        Item = New JQChart.Web.UI.WebControls.LineSeries
        Item.Title = "MyChart"
        Item.XValuesField = "Tolerance"
        Item.YValuesField = "Distribution"
        Item.LineWidth = 1
        Item.Markers.Visible = False
        Item.StrokeStyle = "#006600"

        ' add the series to the series collection
        Chart2.Series.Add(Item)

        ' should be call at the end
        Chart2.DataSource = ViewChart1
        Chart2.DataBind()


    End Sub



Greetings
Roger
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

FlatEarth Theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.193 seconds.