Please excuse if this is not the correct forum for this.
I've searched but didn't find anything on it but I've got an asp:chart (barchart) working fine. I'm adding 5 series and a legend for each. My problem is if I have the legend on the right, the legend items are horizontal and the chart is squished horizontally.
If I dock the legend to the bottom, the legend items are vertical and the chart is squished vertically. I can't find a way to set the orientation of the legend vertical or horizontal. If I have the legend on the right, I'd like to have it vertical so it won't
squish the chart. If I put it on the bottom, I'd like to have it display horizontally.
I also use one of these charts and I do not have any problem in displaying legend. I did not select the position of legend specifically, I just left the default to be as it is. If you post your code, we may get good idea on what is happening.
Here's the small loop where I'm populating the graph. I tried to insert an image but wasn't able to get that in. Thanks :)
Chart1.Series.Clear();
for (int col = 1; col < dsTemp.Tables["dataset1"].Columns.Count; col++)
{
Series series = new Series(dsTemp.Tables["dataset1"].Columns[col].ColumnName);
series.Legend = dsTemp.Tables["dataset1"].Columns[col].ColumnName;
Legend legend = new Legend(dsTemp.Tables["dataset1"].Columns[col].ColumnName);
Chart1.Legends.Add(legend);
for (int row = 0; row < dsTemp.Tables["dataset1"].Rows.Count; row++)
{
series.Points.AddY(dsTemp.Tables["dataset1"].Rows[row][col].ToString());
}
Chart1.Series.Add(series);
}
I tried setting things like Legend.TableStyle, Docking, LegendStyle but nothing seemed to worked.
Yes, removing those two lines makes the chart draw normally (not squished) but there is no legend. Even adding the line...
series.IsVisibleInLegend = true;
doesn't make the legend draw. The examples I found of programatically creating a chart used the two lines above (created a new legend and then adding it to the chart).
Apparently when I was setting the series legend like this and then creating the legend and assigning it to the chart, it messed with the legend. By commenting out the (series.Legend = dsTemp.Tables["dataset1"].Columns[col].ColumnName;) line and bring back in the two lines below, it works as intended. Now when I dock the legend to the bottom the legend draws horizontally. Thanks a bunch for your help. You got me to thinking on it... :)
Legend legend = new Legend(dsTemp.Tables["dataset1"].Columns[col].ColumnName);
Chart1.Legends.Add(legend);
nasman
Member
14 Points
11 Posts
asp chart legend
Feb 08, 2013 07:16 PM|LINK
Please excuse if this is not the correct forum for this.
I've searched but didn't find anything on it but I've got an asp:chart (barchart) working fine. I'm adding 5 series and a legend for each. My problem is if I have the legend on the right, the legend items are horizontal and the chart is squished horizontally. If I dock the legend to the bottom, the legend items are vertical and the chart is squished vertically. I can't find a way to set the orientation of the legend vertical or horizontal. If I have the legend on the right, I'd like to have it vertical so it won't squish the chart. If I put it on the bottom, I'd like to have it display horizontally.
Any help would be appreciated.
Thanks
anilreddy128
Member
118 Points
48 Posts
Re: asp chart legend
Feb 08, 2013 07:25 PM|LINK
Can you post your code?...
I also use one of these charts and I do not have any problem in displaying legend. I did not select the position of legend specifically, I just left the default to be as it is. If you post your code, we may get good idea on what is happening.
Test Engineer
nasman
Member
14 Points
11 Posts
Re: asp chart legend
Feb 08, 2013 07:42 PM|LINK
Here's the small loop where I'm populating the graph. I tried to insert an image but wasn't able to get that in. Thanks :)
Chart1.Series.Clear(); for (int col = 1; col < dsTemp.Tables["dataset1"].Columns.Count; col++) { Series series = new Series(dsTemp.Tables["dataset1"].Columns[col].ColumnName); series.Legend = dsTemp.Tables["dataset1"].Columns[col].ColumnName; Legend legend = new Legend(dsTemp.Tables["dataset1"].Columns[col].ColumnName); Chart1.Legends.Add(legend); for (int row = 0; row < dsTemp.Tables["dataset1"].Rows.Count; row++) { series.Points.AddY(dsTemp.Tables["dataset1"].Rows[row][col].ToString()); } Chart1.Series.Add(series); }I tried setting things like Legend.TableStyle, Docking, LegendStyle but nothing seemed to worked.
anilreddy128
Member
118 Points
48 Posts
Re: asp chart legend
Feb 08, 2013 08:04 PM|LINK
Try removing below lines and see
Test Engineer
nasman
Member
14 Points
11 Posts
Re: asp chart legend
Feb 08, 2013 08:10 PM|LINK
Yes, removing those two lines makes the chart draw normally (not squished) but there is no legend. Even adding the line...
series.IsVisibleInLegend = true;
doesn't make the legend draw. The examples I found of programatically creating a chart used the two lines above (created a new legend and then adding it to the chart).
anilreddy128
Member
118 Points
48 Posts
Re: asp chart legend
Feb 08, 2013 08:16 PM|LINK
<asp:Chart ID="Chart1" runat="server" Height="80px" Width="757px" AlternateText="No Records to Display" >
<Legends>
<asp:Legend Name="Legend1">
</asp:Legend>
</Legends>
<Titles>
<asp:Title Font="Microsoft Sans Serif, 16pt, style=Bold" ForeColor="RoyalBlue"
Name="Title1" Text="Velocity Chart" TextStyle="Emboss">
</asp:Title>
</Titles>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
I did something like above and I did not use those 2 lines of code....
Test Engineer
anilreddy128
Member
118 Points
48 Posts
Re: asp chart legend
Feb 08, 2013 08:17 PM|LINK
can you post image of chart without legends.........
Test Engineer
nasman
Member
14 Points
11 Posts
Re: asp chart legend
Feb 08, 2013 08:18 PM|LINK
Ok, I got it now. I commented back in the two lines above and then commented out the line..
Apparently when I was setting the series legend like this and then creating the legend and assigning it to the chart, it messed with the legend. By commenting out the (series.Legend = dsTemp.Tables["dataset1"].Columns[col].ColumnName;) line and bring back in the two lines below, it works as intended. Now when I dock the legend to the bottom the legend draws horizontally. Thanks a bunch for your help. You got me to thinking on it... :)
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: asp chart legend
Feb 10, 2013 01:14 AM|LINK
Hi,
I'll close your issue.
Anything urgent, please feel free to create a new thread to continue.