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

Many columns with same value

1 Answer 75 Views
Design Time (Visual Designer & Tools)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Erica
Top achievements
Rank 1
Erica asked on 12 Aug 2015, 02:27 PM

Hi, I have a dynamic column chart in code-behind. I take the values from a table in my database and the values are divided by month (each month is a row in my table and each column is a group). However, my chart is showing 12 different columns with the same value for the same group. For example: in January, I have the value 10 and in February value 20 for Group A. In the chart, it is showing 12 columns with the value 10 in January and 12 columns with the value 20 in February. (I'm sorry I couldn't post a picture). I need only one column in each month. Can anyone help me with that?

 ​

At first, I'm just getting a value from one of my table columns as a test.

Here is my code:

 

    Dim chartGroups As New RadHtmlChart()
    chartGroups.ID = "chartGroups"
    chartGroups.Width = Unit.Pixel(1200)
    chartGroups.Height = Unit.Pixel(600)
 
    chartGroups.Legend.Appearance.Position = Telerik.Web.UI.HtmlChart.ChartLegendPosition.Bottom
 
    chartGroups.PlotArea.XAxis.Items.Add("Jan")
    chartGroups.PlotArea.XAxis.Items.Add("Feb")
    chartGroups.PlotArea.XAxis.Items.Add("Mar")
    chartGroups.PlotArea.XAxis.Items.Add("Apr")
    chartGroups.PlotArea.XAxis.Items.Add("May")
    chartGroups.PlotArea.XAxis.Items.Add("Jun")
    chartGroups.PlotArea.XAxis.Items.Add("Jul")
    chartGroups.PlotArea.XAxis.Items.Add("Aug")
    chartGroups.PlotArea.XAxis.Items.Add("Sep")
    chartGroups.PlotArea.XAxis.Items.Add("Oct")
    chartGroups.PlotArea.XAxis.Items.Add("Nov")
    chartGroups.PlotArea.XAxis.Items.Add("Dec")
 
    chartGroups.PlotArea.XAxis.TitleAppearance.Text = "Month"
    chartGroups.PlotArea.YAxis.TitleAppearance.Text = "Total"
 
    Dim chartDataTable As DataSet
    chartDataTable = Program_TypeGrouping_Controller.GetOrderIntake_ByYear(ddlYear.SelectedValue, 0)
 
Dim npColumnSeries As New ColumnSeries
    Dim groupIntake As New SeriesItem
    Using reader As DataTableReader = chartDataTable.CreateDataReader()
 
        While reader.Read()
             
            Dim test As Double
 
            If reader.IsDBNull(3) Then
                test = 0
            Else
                test = reader(3)
            End If
 
             
            npColumnSeries.Stacked = False
            groupIntake.Name = reader.GetName(3)
            npColumnSeries.Spacing = 0
            groupIntake.YValue = test
            npColumnSeries.LabelsAppearance.Visible = False
 
            npColumnSeries.SeriesItems.Add(groupIntake.YValue)
            chartGroups.PlotArea.Series.Add(npColumnSeries)
 
        End While
    End Using
 
    HtmlChartHolder.Controls.Add(chartGroups)

 

1 Answer, 1 is accepted

Sort by
0
Slav
Telerik team
answered on 17 Aug 2015, 11:50 AM
Hello Erica,

If I understand your scenario correctly, you need to create one ColumnSeries with a CategorySeriesItem for each category of the HtmlChart. Your current implementation inserts a ColumnSeries instance for each record in the data source, which result in having multiple columns in each category, instead of only one.

You can change this by inserting the ColumnSeries instance only once, as shown in the sample page I attached to this post. I would also suggest checking the following help article for a better understanding of how column series are configured: http://docs.telerik.com/devtools/aspnet-ajax/controls/htmlchart/chart-types/column-chart

Regards,
Slav
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
Design Time (Visual Designer & Tools)
Asked by
Erica
Top achievements
Rank 1
Answers by
Slav
Telerik team
Share this question
or