user2703720
user2703720

Reputation: 11

Using Variable for MS Chart Series names

I'm using an MS Chart in my webpage and would like the series name to be the value of one of the data sources columns.

In my example, I would like to use the value in the field SalesYear to name the series instead of the static value Year1. How can I do that?

<asp:Chart
ID="chtPipelinePerformance"
runat="server" 
DataSourceID="dsPipelinePerformance"
>
<Series>
   <asp:Series
     Name="Year1"
     charttype="StackedColumn"
     color="RoyalBlue"
     XValueMember="SalesYear"
     YValueMembers="PipelineYear1"
     Font="Microsoft Sans Serif, 10pt, style=Bold"
     >
   </asp:Series>
</Series>
</asp:Chart>

Upvotes: 1

Views: 744

Answers (1)

Nikolaj Zander
Nikolaj Zander

Reputation: 1270

Adding a Series in Codebehind:

Dim seriesName as String = "Myname"

chtPipelinePerformance.Series.Add(New Series(seriesName))

Databinding in Codebehind:

chtPipelinePerformance.DataBindTable(dataSource, xField)

You can databind your chart in codebind and do this to manipulate each series:

For Each s As Series In chtPipelinePerformance.Series
                s.ChartType = SeriesChartType.StackedColumn
                s.Name = s.XValueMember
            Next

Upvotes: 1

Related Questions