This is a migrated thread and some comments may be shown as answers.

Data Appearing in Accurately In Stack Bar Chart in Report

4 Answers 80 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Naginder Singh
Top achievements
Rank 1
Naginder Singh asked on 18 Jan 2010, 04:19 PM

I am working on a report , where i have to display  a stackbar chart .  But chart does not display accurate data .
please find attachement for report pdf and code file . please help me Asap.




  Private Sub Chart1_NeedDataSource(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles chart1.NeedDataSource  
        Try 
            Dim StrSqlConnection As String = ConnectionString  
            If Trim(StrSqlConnection) <> "" Then 
                If Not ObjSqlCon Is Nothing Then 
                    ObjSqlCon = Nothing 
                End If 
                ObjSqlCon = New SqlConnection(StrSqlConnection)  
                ObjSqlCon.Open()  
                If ObjSqlCon.State = ConnectionState.Open Then                      
                    Dim chart1 As Telerik.Reporting.Processing.Chart = CType(sender, Telerik.Reporting.Processing.Chart)  
                    Dim defChart As Telerik.Reporting.Chart = DirectCast(Chart1.ItemDefinition, Telerik.Reporting.Chart)  
                    Dim ProjectRpt As New ProjectTrendDstTableAdapters.ReportProjectTrendAnalysisTableAdapter  
                    ProjectRpt.Connection = ObjSqlCon  
                    Dim ProjectDst As New ProjectTrendDst.ReportProjectTrendAnalysisDataTable  
                    ProjectDst = ProjectRpt.GetData  
                    SalesPersonQChart.DataSource = ProjectDst  
                    defChart.DataGroupColumn = "Status"                      
                    defChart.PlotArea.XAxis.DataLabelsColumn = "Territory" 
                    defChart.Legend.Appearance.GroupNameFormat = "#VALUE" 
                End If 
            End If 
        Catch ex As Exception  
 
        Finally 
            If ObjSqlCon IsNot Nothing Then 
                ObjSqlCon = Nothing 
            End If 
        End Try 
 
    End Sub 
Thanks and Regards,
Naginder Singh

4 Answers, 1 is accepted

Sort by
0
Chavdar
Telerik team
answered on 21 Jan 2010, 09:54 AM
Hi Naginder Singh,

There are two ways to make the data appear correctly. The first one is to modify the data source so that it includes records for the missing values, i.e. instead of missing records there should be records with value 0 for the respective X axis positions. The other way is to create and add the chart series items programmatically as explained in the following thread: Graph for each group. Hope it helps.

Kind regards,
Chavdar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Naginder Singh
Top achievements
Rank 1
answered on 21 Jan 2010, 02:30 PM
Hi Chavdar,
                   Its not possible to me make dataset like that you have suggested. Nor i tried with thread you suggested but it also not work. Please give an exmple. So that it could work for me.

Thanks,
Naginder SIngh
0
Chavdar
Telerik team
answered on 26 Jan 2010, 09:39 AM
Hi Naginder Singh,

Here is a sample code snippet which illustrates how to achieve the desired functionality:

Private Sub Chart1_NeedDataSource(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Chart1.NeedDataSource
    Dim chart = CType(sender, Telerik.Reporting.Processing.Chart)
    Dim chartDef = CType(chart.ItemDefinition, Telerik.Reporting.Chart)
    Dim dataTable = GetDataSource()
    Dim dataRow As DataRow
    chartDef.Series.Clear()
    Dim axisLabels As New List(Of String)
    For Each dataRow In dataTable.Rows
        Dim status = CType(dataRow("Status"), String)
        Dim series = chartDef.Series.GetByName(status)
        If series Is Nothing Then
            series = New Telerik.Reporting.Charting.ChartSeries(status)
            series.Type = Charting.ChartSeriesType.StackedBar
            chartDef.Series.Add(series)
        End If
        Dim value As Integer = CType(dataRow("Value"), Integer)
        Dim seriesItem = New Telerik.Reporting.Charting.ChartSeriesItem()
        seriesItem.YValue = value
 
        Dim territory = CType(dataRow("Territory"), String)
        If Not axisLabels.Contains(territory) Then
            axisLabels.Add(territory)
        End If
        seriesItem.XValue = axisLabels.IndexOf(territory)
        series.Items.Add(seriesItem)
    Next
 
    chartDef.PlotArea.XAxis.AutoScale = False
    chartDef.PlotArea.XAxis.AutoShrink = False
    chartDef.PlotArea.XAxis.Items.Clear()
    Dim axisLabel As String
    For Each axisLabel In axisLabels
        Dim axisItem = New Telerik.Reporting.Charting.ChartAxisItem()
        axisItem.TextBlock.Text = axisLabel
        axisItem.Value = axisLabels.IndexOf(axisLabel)
        chartDef.PlotArea.XAxis.Items.Add(axisItem)
    Next
End Sub
 
Function GetDataSource() As DataTable
    Dim table = New DataTable()
    table.Columns.Add("Territory", GetType(String))
    table.Columns.Add("Status", GetType(String))
    table.Columns.Add("Value", GetType(Integer))
    table.Rows.Add(New Object() {"Guangxi", "Open", 1})
    table.Rows.Add(New Object() {"Jilin", "Open", 2})
    table.Rows.Add(New Object() {"Shandong", "Open", 2})
    table.Rows.Add(New Object() {"Shanxi", "Lost", 18})
    table.Rows.Add(New Object() {"Shanxi", "Open", 2})
    table.Rows.Add(New Object() {"Shanxi", "Ordered", 2})
    table.Rows.Add(New Object() {"Yunnan", "Open", 2})
    table.Rows.Add(New Object() {"Zheijang", "Open", 2})
    Return table
End Function

Hope it helps.

Best wishes,
Chavdar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Naginder Singh
Top achievements
Rank 1
answered on 26 Jan 2010, 11:02 AM
It Works for me . Really many - many thanks for you.

Tags
General Discussions
Asked by
Naginder Singh
Top achievements
Rank 1
Answers by
Chavdar
Telerik team
Naginder Singh
Top achievements
Rank 1
Share this question
or