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

PivotGrid to HTMLChart

1 Answer 46 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Hani
Top achievements
Rank 1
Hani asked on 06 Jul 2015, 11:34 PM

Hello,

 

First i don't know if this is the correct place to post or i should have posted in the HTMLChart section,

 

Anyways I'm binding RadHTML Chart to a PivotGrid and everything is working perfectly excepts that the series names of the htmlchart are in an incorrect order, for example:

 

If i have the below pivot:

 

   Name   :   Col1   |    Col2   |   Col3   |   Col4   

   A          :      1      |      4      |      5     |      2

   B          :      7      |      3      |      2     |      1

   C          :      5      |      1      |      4     |      2

 

I get it in the HTML Chart as follows:

 

X Axis name of Col3 with Series and Y value of Col2 and so on for the rest

------------------------------------------------------------------------------------------------------------------

The ASP code is:

 

<telerik:RadPivotGrid ID="RadPivotGrid1" runat="server" DataSourceID="SqlDataSource1" OnCellDataBound="RadPivotGrid1_CellDataBound">
                                    <Fields>
                                        <telerik:PivotGridColumnField UniqueName="column" DataField="ProjectName" Caption="Project"></telerik:PivotGridColumnField>
                                        <telerik:PivotGridRowField UniqueName="column1" DataField="DisplayName" Caption="Name"></telerik:PivotGridRowField>
                                        <telerik:PivotGridAggregateField GrandTotalAggregateFormatString="" CalculationExpression="" UniqueName="column2" DataField="Duration" Caption="Duration">
                                            <TotalFormat Level="0" Axis="Rows" TotalFunction="NoCalculation" SortOrder="Ascending"></TotalFormat>
                                        </telerik:PivotGridAggregateField>
                                    </Fields>
 
                                    <ConfigurationPanelSettings DefaultDeferedLayoutUpdate="True"></ConfigurationPanelSettings>
                                </telerik:RadPivotGrid>
                                <telerik:RadHtmlChart ID="RadHtmlChart1" runat="server" DataSourceID="SqlDataSource1">
                                    <Legend>
                                        <Appearance Position="Bottom">
                                        </Appearance>
                                    </Legend>
                                </telerik:RadHtmlChart>

I have SQLDataSource which is populated from Code behind, The code behind as follows:

    Private columnNames As New HashSet(Of String)()
    Private columnSeriesByRowName As New Dictionary(Of String, ColumnSeries)()
    Protected Sub RadPivotGrid1_CellDataBound(sender As Object, e As PivotGridCellDataBoundEventArgs)
        Dim dataCell As PivotGridDataCell = TryCast(e.Cell, PivotGridDataCell)
        If columnNames.Count = 0 Then
            Me.RadHtmlChart1.PlotArea.XAxis.Items.Clear()
            Me.RadHtmlChart1.PlotArea.Series.Clear()
        End If
        If dataCell IsNot Nothing AndAlso dataCell.CellType = PivotGridDataCellType.DataCell Then
            Dim rowName As String = GetName(dataCell.ParentRowIndexes)
            Dim columnName As String = GetName(dataCell.ParentColumnIndexes)
            columnName = columnName.Replace("'", " ")
            If columnNames.Add(columnName) Then
                Dim axisItem As New AxisItem(columnName)
                RadHtmlChart1.PlotArea.XAxis.Items.Add(axisItem)
            End If
            RadHtmlChart1.PlotArea.XAxis.LabelsAppearance.RotationAngle = 45
            Dim columnSeries As ColumnSeries = Nothing
 
            If columnSeriesByRowName.ContainsKey(rowName) Then
                columnSeries = columnSeriesByRowName(rowName)
            Else
                columnSeries = New ColumnSeries()
                columnSeriesByRowName.Add(rowName, columnSeries)
                columnSeries.Name = rowName
                ' columnSeries.LabelsAppearance.DataFormatString = "C"
                columnSeries.LabelsAppearance.Visible = False
                columnSeries.LabelsAppearance.RotationAngle = 45
                columnSeries.TooltipsAppearance.DataFormatString = "{0} " & rowName
                columnSeries.Stacked = True
                Me.RadHtmlChart1.PlotArea.Series.Add(columnSeries)
            End If
            Dim item As New CategorySeriesItem()
            Dim value As Decimal = 0
            If e.Cell.DataItem IsNot Nothing AndAlso Decimal.TryParse(e.Cell.DataItem.ToString(), value) Then
                item.Y = value
            Else
                item.Y = Nothing
            End If
            columnSeries.SeriesItems.Add(item)
        End If
    End Sub
 
    Private Function GetName(indexes As Object()) As String
        Dim builder As New StringBuilder()
        For Each index As Object In indexes
            builder.Append(index.ToString())
            builder.Append(" / ")
        Next
        builder.Remove(builder.Length - 3, 3)
        Return builder.ToString()
    End Function
 
    Private Sub PopulateSQLDataSource()
 
        SqlDataSource1.SelectCommand = "SELECT Project.ProjectName, SUM( DATEDIFF(HOUR, DbProvider_Classes.Start, DbProvider_Classes.[End])) AS Duration, Users.DisplayName
FROM     Project INNER JOIN
                  DbProvider_Classes ON Project.ProjectID = DbProvider_Classes.ProjectID INNER JOIN
                  Users ON DbProvider_Classes.UserID = Users.UserID
                  INNER JOIN Tasks ON DbProvider_Classes.TaskID = Tasks.TaskID
                  WHERE Tasks.DepartmentID <> 6
                  GROUP BY Project.ProjectName , Users.DisplayName ORDER BY Project.ProjectName ASC"
        SqlDataSource1.Select(DataSourceSelectArguments.Empty)
        SqlDataSource1.DataBind()
        RadPivotGrid1.DataBind()
    End Sub
Private Sub btnViewAll_Click(sender As Object, e As EventArgs) Handles btnViewAll.Click
        PopulateSQLDataSource()
        lblReportDate.Text = "Report Date: Until " & Today.Date.ToString
 
    End Sub

 

If i create the same report with report designer everything works fine and i can load the generated report file from report viewer within my page but i want the client side capabilities of the HTMLChart

 

Thanks

 

 

 

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 09 Jul 2015, 12:08 PM
Hello Hani,

The provided code looks absolutely correct to me and there is no obvious reason for the described issue to appear. The chart integration works properly in a sample application on my end.
See the demo below:
http://demos.telerik.com/aspnet-ajax/pivotgrid/examples/applicationscenarios/chartintegration/defaultcs.aspx

In this case it will be best if you can open a regular support ticket and send us sample runnable version of your application that demonstrates the issue. Thus we will be able to inspect it locally and advise you further.

Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
PivotGrid
Asked by
Hani
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or