none
Legend Text problem in MS charting control in c# asp.net

    Question

  • Hi,

    I'm working on MS charting control for different chart types. i have used a single series for the charts. The problem is, the legend text data is not displayed for non shape charts. please provide me a solution for this.
    this is d piece of code tht i'm using:

    on run time , the legend displays only one color with #AXISLABEL under one column and #VALX under another column.. 

     
    how can i fix the legend column data values.. those expressions are not getting evaluated.

    • Edited by vidya_01 Friday, December 18, 2009 11:25 AM
    Friday, December 18, 2009 9:49 AM

Answers

All replies

  • Can you please provide a snapshot?

    It will clear what you are looking for...
    Monday, December 21, 2009 9:00 AM
  • Hi,
    thanks for replying. But how do i provide a snapshot of it? I'm not able to attach the image or copy paste it here in the forum.
    regards,
    vidya
    Monday, December 21, 2009 9:12 AM
  • Hi,
    thanks for replying. But how do i provide a snapshot of it? I'm not able to attach the image or copy paste it here in the forum.
    regards,
    vidya
    Monday, December 21, 2009 9:15 AM
  • You can give url of the image uploaded here.

    So, you put the image on some website that gives free image uploading facility like photobucket.com or any other site.

    Then you can copy/paste image from there.
    Dhruv M. Patel
    Monday, December 21, 2009 12:29 PM
  • hey u can view the problem page in the following links :


    http://s1005.photobucket.com/albums/af174/vid_s21/

    Tuesday, December 22, 2009 5:45 AM
  • I got your point.

    You are actually applying the palette style to your chart, not your series.

    Looks like you are not fully aware of the parts of the chart. The points you have drawn on chart actually represent a single series.

    So, to make your colors uniform, you need to apply the palette style to your series.

    If you use following code, your will see the difference. 
    Somechart.Series["series"].PaletteStyle = ChartColorPalette.BrightPastel;
    Hope, this helps
    Dhruv M. Patel
    Wednesday, December 23, 2009 7:52 AM
  • Hi, thanks. 
    that is not the problem. the problem is with data display in the legend for non shape charts.
    you can see the code that i'm pasting in this reply to better understand. Is there any way to display different values in the legend columns?





    private void chartLoad() { Series Series1 = new Series(); fd = Session["fromDate"].ToString(); td = Session["toDate"].ToString(); uc = new UserClass(); dt = uc.getTransGraph(Session["Uid"].ToString(), fd, td); if (dt == null) { lblGraphRes.Text = "No transactions for the specified date"; } else { Chart1.DataSource = dt; Chart1.DataBind(); Chart1.Series["Series1"].XValueMember = "SubCategory"; Chart1.Series["Series1"].YValueMembers = "Amount"; // Random random = new Random(); foreach (DataRow dr in dt.Rows) { //Series Series2 = new Series(); Chart1.Series["Series1"].Points.AddXY(dt.Rows[0]["SubCategory"].ToString(), dt.Rows[0]["Amount"]); Chart1.Series["Series1"].SetCustomProperty("CustomX", dt.Rows[0]["SubCategory"].ToString()); Chart1.Series["Series1"].SetCustomProperty("CustomY", dt.Rows[0]["Amount"].ToString()); // Chart1.Series.Add(Series2); } Chart1.Series["Series1"].ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), ddlChartType.Items[ddlChartType.SelectedIndex].Text, true); // Show point labels Chart1.Series["Series1"].IsValueShownAsLabel = true; this.Chart1.Titles["Title1"].Text = "Expenses Graph"; Chart1.ChartAreas["ChartArea1"].AxisX.Title = "SubCategory --->"; Chart1.ChartAreas["ChartArea1"].AxisX.TitleFont = new Font("Arial", 12, FontStyle.Bold); Chart1.ChartAreas["ChartArea1"].AxisY.Title = "Amount --->"; Chart1.ChartAreas["ChartArea1"].AxisY.TitleFont = new Font("Arial", 12, FontStyle.Bold); Chart1.Series["Series1"]["PointWidth"] = "0.4"; Chart1.Series["Series1"]["ShowMarkerLines"] = "True"; // this.Chart1.Series["Series1"]["PieLabelStyle"] = "outside"; Chart1.Series["Series1"].ToolTip = "Data Point Y Value: #VALY{C}"; Chart1.Series["Series1"].ChartArea = "ChartArea1"; //Chart1.Legends.Add("Default"); Chart1.Legends.Add(new Legend("Default")); Chart1.Series["Series1"].Legend = "Default"; // this.Chart1.Legends["Default"].Enabled = true; // Add header separator of type line Chart1.Legends["Default"].HeaderSeparator = LegendSeparatorStyle.Line; Chart1.Legends["Default"].HeaderSeparatorColor = Color.Gray; Chart1.Legends["Default"].Title = "Chart details"; Chart1.Legends["Default"].Alignment = StringAlignment.Center; // Set the title separator type Chart1.Legends["Default"].TitleSeparator = LegendSeparatorStyle.Line; // Set the color of the title separator Chart1.Legends["Default"].TitleSeparatorColor = Color.Black; Chart1.Legends["Default"].TitleFont = new Font("Arial", 12, FontStyle.Bold); // Add Color column LegendCellColumn firstColumn = new LegendCellColumn(); firstColumn.ColumnType = LegendCellColumnType.SeriesSymbol; firstColumn.HeaderText = "Color"; firstColumn.HeaderBackColor = Color.WhiteSmoke; Chart1.Legends["Default"].CellColumns.Add(firstColumn); // Add Legend Text column LegendCellColumn secondColumn = new LegendCellColumn(); secondColumn.ColumnType = LegendCellColumnType.Text; secondColumn.HeaderText = "SubCategory"; // secondColumn.Text = "#AXISLABEL"; secondColumn.Text = "#CUSTOMPROPERTY(CustomX)"; secondColumn.HeaderBackColor = Color.WhiteSmoke; Chart1.Legends["Default"].CellColumns.Add(secondColumn); // Add Legend Text column LegendCellColumn thirdColumn = new LegendCellColumn(); thirdColumn.ColumnType = LegendCellColumnType.Text; thirdColumn.HeaderText = "Amount"; // thirdColumn.Text = "#VALX ( #VAL{C} ) #PERCENT"; thirdColumn.Text = "#CUSTOMPROPERTY(CustomY)"; thirdColumn.HeaderBackColor = Color.WhiteSmoke; Chart1.Legends["Default"].CellColumns.Add(thirdColumn); Chart1.Legends["Default"].IsTextAutoFit = false; Chart1.Legends["Default"].TextWrapThreshold = 100; // Set new legend text font Chart1.Legends["Default"].Font = new Font("Arial", 10, FontStyle.Bold); // Set legend text color Chart1.Legends["Default"].ForeColor = Color.Black; Chart1.Palette = ChartColorPalette.BrightPastel; Chart1.Series["Series1"].Palette = ChartColorPalette.BrightPastel; Chart1.Series["Series1"].IsVisibleInLegend = true; // Disable X axis margin Chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false; Chart1.ChartAreas["ChartArea1"].Area3DStyle.IsClustered = false; // Enable 3D Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true; Chart1.ChartAreas["ChartArea1"].AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount; Chart1.Series["Series1"].LegendText = "#AXISLABEL"; } }
    Wednesday, December 23, 2009 11:31 AM
  • Hi, thanks. 
    that is not the problem. the problem is with data display in the legend for non shape charts.
    you can see the code that i'm pasting in this reply to better understand. Is there any way to display different values in the legend columns?





    private void chartLoad() { Series Series1 = new Series(); fd = Session["fromDate"].ToString(); td = Session["toDate"].ToString(); uc = new UserClass(); dt = uc.getTransGraph(Session["Uid"].ToString(), fd, td); if (dt == null) { lblGraphRes.Text = "No transactions for the specified date"; } else { Chart1.DataSource = dt; Chart1.DataBind(); Chart1.Series["Series1"].XValueMember = "SubCategory"; Chart1.Series["Series1"].YValueMembers = "Amount"; // Random random = new Random(); foreach (DataRow dr in dt.Rows) { //Series Series2 = new Series(); Chart1.Series["Series1"].Points.AddXY(dt.Rows[0]["SubCategory"].ToString(), dt.Rows[0]["Amount"]); Chart1.Series["Series1"].SetCustomProperty("CustomX", dt.Rows[0]["SubCategory"].ToString()); Chart1.Series["Series1"].SetCustomProperty("CustomY", dt.Rows[0]["Amount"].ToString()); // Chart1.Series.Add(Series2); } Chart1.Series["Series1"].ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), ddlChartType.Items[ddlChartType.SelectedIndex].Text, true); // Show point labels Chart1.Series["Series1"].IsValueShownAsLabel = true; this.Chart1.Titles["Title1"].Text = "Expenses Graph"; Chart1.ChartAreas["ChartArea1"].AxisX.Title = "SubCategory --->"; Chart1.ChartAreas["ChartArea1"].AxisX.TitleFont = new Font("Arial", 12, FontStyle.Bold); Chart1.ChartAreas["ChartArea1"].AxisY.Title = "Amount --->"; Chart1.ChartAreas["ChartArea1"].AxisY.TitleFont = new Font("Arial", 12, FontStyle.Bold); Chart1.Series["Series1"]["PointWidth"] = "0.4"; Chart1.Series["Series1"]["ShowMarkerLines"] = "True"; // this.Chart1.Series["Series1"]["PieLabelStyle"] = "outside"; Chart1.Series["Series1"].ToolTip = "Data Point Y Value: #VALY{C}"; Chart1.Series["Series1"].ChartArea = "ChartArea1"; //Chart1.Legends.Add("Default"); Chart1.Legends.Add(new Legend("Default")); Chart1.Series["Series1"].Legend = "Default"; // this.Chart1.Legends["Default"].Enabled = true; // Add header separator of type line Chart1.Legends["Default"].HeaderSeparator = LegendSeparatorStyle.Line; Chart1.Legends["Default"].HeaderSeparatorColor = Color.Gray; Chart1.Legends["Default"].Title = "Chart details"; Chart1.Legends["Default"].Alignment = StringAlignment.Center; // Set the title separator type Chart1.Legends["Default"].TitleSeparator = LegendSeparatorStyle.Line; // Set the color of the title separator Chart1.Legends["Default"].TitleSeparatorColor = Color.Black; Chart1.Legends["Default"].TitleFont = new Font("Arial", 12, FontStyle.Bold); // Add Color column LegendCellColumn firstColumn = new LegendCellColumn(); firstColumn.ColumnType = LegendCellColumnType.SeriesSymbol; firstColumn.HeaderText = "Color"; firstColumn.HeaderBackColor = Color.WhiteSmoke; Chart1.Legends["Default"].CellColumns.Add(firstColumn); // Add Legend Text column LegendCellColumn secondColumn = new LegendCellColumn(); secondColumn.ColumnType = LegendCellColumnType.Text; secondColumn.HeaderText = "SubCategory"; // secondColumn.Text = "#AXISLABEL"; secondColumn.Text = "#CUSTOMPROPERTY(CustomX)"; secondColumn.HeaderBackColor = Color.WhiteSmoke; Chart1.Legends["Default"].CellColumns.Add(secondColumn); // Add Legend Text column LegendCellColumn thirdColumn = new LegendCellColumn(); thirdColumn.ColumnType = LegendCellColumnType.Text; thirdColumn.HeaderText = "Amount"; // thirdColumn.Text = "#VALX ( #VAL{C} ) #PERCENT"; thirdColumn.Text = "#CUSTOMPROPERTY(CustomY)"; thirdColumn.HeaderBackColor = Color.WhiteSmoke; Chart1.Legends["Default"].CellColumns.Add(thirdColumn); Chart1.Legends["Default"].IsTextAutoFit = false; Chart1.Legends["Default"].TextWrapThreshold = 100; // Set new legend text font Chart1.Legends["Default"].Font = new Font("Arial", 10, FontStyle.Bold); // Set legend text color Chart1.Legends["Default"].ForeColor = Color.Black; Chart1.Palette = ChartColorPalette.BrightPastel; Chart1.Series["Series1"].Palette = ChartColorPalette.BrightPastel; Chart1.Series["Series1"].IsVisibleInLegend = true; // Disable X axis margin Chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false; Chart1.ChartAreas["ChartArea1"].Area3DStyle.IsClustered = false; // Enable 3D Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true; Chart1.ChartAreas["ChartArea1"].AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount; Chart1.Series["Series1"].LegendText = "#AXISLABEL"; } }

    For giving a try, please comment the highlighted code.

    Because, if you do not create legends and just put the highlighted code, thenalso you will see legend information of the series.
    So, I am thinking it is createing problem for you.

    Dhruv M. Patel
    Wednesday, December 23, 2009 11:54 AM
  • hi. i commented those lines as u suggested. but it didn't make any difference . 
    can you please look at the image at this link and understand the problem?

    http://i1005.photobucket.com/albums/af174/vid_s21/chartlegendproblem.jpg?t=1261624757
    Thursday, December 24, 2009 3:21 AM
  • Place this modified else statement block to your code, and roll your chart the way you envisioned.
    string[] colorList = GetColorList();
    
    Legend seriesLegend = new SeriesLegend();
    seriesLegend.Title = "Chart details";
    seriesLegend.HeaderSeparator = LegendSeparatorStyle.Line;
    seriesLegend.HeaderSeparatorColor = Color.Gray;
    seriesLegend.Alignment = StringAlignment.Center;
    seriesLegend.TitleSeparator = LegendSeparatorStyle.Line;
    seriesLegend..TitleSeparatorColor = Color.Black;
    seriesLegend.TitleFont = new Font("Arial", 12, FontStyle.Bold);
    
    for (int i=0; i<dt.Rows.Count; i++)
    {
            Chart1.Series["Series1"].Points.AddXY(dt.Rows[i]["SubCategory"].ToString(), dt.Rows[i]["Amount"]);
            Chart1.Series["Series1"].SetCustomProperty("CustomX", dt.Rows[i]["SubCategory"].ToString());
            Chart1.Series["Series1"].SetCustomProperty("CustomY", dt.Rows[i]["Amount"].ToString());
    
            seriesLegend.CustomItems.Add(new LegendItem(dt.Rows[i]["SubCategory"].ToString(), Chart1.Series["Series1"].Points[Chart1.Series["Series1"].Points.Count - 1].Color, ""));
    }
               
    Chart1.Series["Series1"].ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), ddlChartType.Items[ddlChartType.SelectedIndex].Text, true);
    
    // Show point labels
    Chart1.Series["Series1"].IsValueShownAsLabel = true;
    Chart1.Titles["Title1"].Text = "Expenses Graph";
    
    Chart1.ChartAreas["ChartArea1"].AxisX.Title = "SubCategory --->";
    Chart1.ChartAreas["ChartArea1"].AxisX.TitleFont = new Font("Arial", 12, FontStyle.Bold);
    Chart1.ChartAreas["ChartArea1"].AxisY.Title = "Amount --->";
    Chart1.ChartAreas["ChartArea1"].AxisY.TitleFont = new Font("Arial", 12, FontStyle.Bold);
    Chart1.Series["Series1"]["PointWidth"] = "0.4";
               
    Chart1.Series["Series1"]["ShowMarkerLines"] = "True";
    Chart1.Series["Series1"].ToolTip = "Data Point Y Value: #VALY{C}";
    
    Chart1.Series["Series1"].ChartArea = "ChartArea1";
    
    Chart1.Legends.Add(new Legend(seriesLegend));
    Chart1.Series["Series1"].IsVisibleInLegend = false;
    
    // Disable X axis margin
    Chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false;
    Chart1.ChartAreas["ChartArea1"].Area3DStyle.IsClustered = false;
    
    // Enable 3D
    Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
    
    
    Chart1.ChartAreas["ChartArea1"].AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;


    ColorList Provider Function :

    public string[] GetColorList()
    {
                StringBuilder colors = new StringBuilder();
                List<String> SystemColors = new List<String>();
                
                foreach (String colorName in KnownColor.GetNames(typeof(KnownColor)))
                {
                    if (Color.FromName(colorName).IsSystemColor)
                        SystemColors.Add(colorName);
                }
    
                foreach (String color in SystemColors)
                    colors.Append(color + ";");
    
                string colorList = colors.ToString();
                return colorList.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
    }


    You will see your points displayed in two columns...but I think, you will need to deal with the Count display that appeared in third LegendCellColumn.

    Hope, I am helpful.

    Thanks,
    Dhruv M. Patel
    Thursday, December 24, 2009 9:14 AM
  • Hey,
    Thank u so much. But its not helping :( 
    the legend just doesn't display different subcategory names and amount in the respective columns.
    It just shows the last value that was fetched from the datatable in the for loop.
    Monday, December 28, 2009 4:22 AM
  • It was the best I can do for you after understanding your snap....

    The custom items will be your solution to work on.


    Thanks,
    Dhruv M. Patel
    Monday, December 28, 2009 6:42 AM
  • Yes,
    Thank you. I think its got something to do with LegendCellColumn.text . i'm not able to access each cell of the legend column.so that is where the problem is. Not able to load each value into different cells of each column in the custom legend cells.
    I appreciate your efforts. It helped me to get a better understanding of charts.
    Thank u again.
    Monday, December 28, 2009 10:00 AM
  • Place this modified else statement block to your code, and roll your chart the way you envisioned.
    string[] colorList = GetColorList();
    
    
    
    Legend seriesLegend = new SeriesLegend();
    
    seriesLegend.Title = "Chart details";
    
    seriesLegend.HeaderSeparator = LegendSeparatorStyle.Line;
    
    seriesLegend.HeaderSeparatorColor = Color.Gray;
    
    seriesLegend.Alignment = StringAlignment.Center;
    
    seriesLegend.TitleSeparator = LegendSeparatorStyle.Line;
    
    seriesLegend..TitleSeparatorColor = Color.Black;
    
    seriesLegend.TitleFont = new Font("Arial", 12, FontStyle.Bold);
    
    
    
    for (int i=0; i<dt.Rows.Count; i++)
    
    {
    
        Chart1.Series["Series1"].Points.AddXY(dt.Rows[i]["SubCategory"].ToString(), dt.Rows[i]["Amount"]);
    
        Chart1.Series["Series1"].SetCustomProperty("CustomX", dt.Rows[i]["SubCategory"].ToString());
    
        Chart1.Series["Series1"].SetCustomProperty("CustomY", dt.Rows[i]["Amount"].ToString());
    
    
    
        seriesLegend.CustomItems.Add(new LegendItem(dt.Rows[i]["SubCategory"].ToString(), Chart1.Series["Series1"].Points[Chart1.Series["Series1"].Points.Count - 1].Color, ""));
    
    }
    
          
    
    Chart1.Series["Series1"].ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), ddlChartType.Items[ddlChartType.SelectedIndex].Text, true);
    
    
    
    // Show point labels
    
    Chart1.Series["Series1"].IsValueShownAsLabel = true;
    
    Chart1.Titles["Title1"].Text = "Expenses Graph";
    
    
    
    Chart1.ChartAreas["ChartArea1"].AxisX.Title = "SubCategory --->";
    
    Chart1.ChartAreas["ChartArea1"].AxisX.TitleFont = new Font("Arial", 12, FontStyle.Bold);
    
    Chart1.ChartAreas["ChartArea1"].AxisY.Title = "Amount --->";
    
    Chart1.ChartAreas["ChartArea1"].AxisY.TitleFont = new Font("Arial", 12, FontStyle.Bold);
    
    Chart1.Series["Series1"]["PointWidth"] = "0.4";
    
          
    
    Chart1.Series["Series1"]["ShowMarkerLines"] = "True";
    
    Chart1.Series["Series1"].ToolTip = "Data Point Y Value: #VALY{C}";
    
    
    
    Chart1.Series["Series1"].ChartArea = "ChartArea1";
    
    
    
    Chart1.Legends.Add(new Legend(seriesLegend));
    
    Chart1.Series["Series1"].IsVisibleInLegend = false;
    
    
    
    // Disable X axis margin
    
    Chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false;
    
    Chart1.ChartAreas["ChartArea1"].Area3DStyle.IsClustered = false;
    
    
    
    // Enable 3D
    
    Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
    
    
    
    
    
    Chart1.ChartAreas["ChartArea1"].AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;
    
    


    ColorList Provider Function :

    public string[] GetColorList()
    
    {
    
          StringBuilder colors = new StringBuilder();
    
          List<String> SystemColors = new List<String>();
    
          
    
          foreach (String colorName in KnownColor.GetNames(typeof(KnownColor)))
    
          {
    
            if (Color.FromName(colorName).IsSystemColor)
    
              SystemColors.Add(colorName);
    
          }
    
    
    
          foreach (String color in SystemColors)
    
            colors.Append(color + ";");
    
    
    
          string colorList = colors.ToString();
    
          return colorList.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
    
    }
    
    


    You will see your points displayed in two columns...but I think, you will need to deal with the Count display that appeared in third LegendCellColumn.

    Hope, I am helpful.

    Thanks,
    Dhruv M. Patel


    hello
        Can you help to add the legend is not clear how to realize I have, this is the code that I occupy

     

    Chart1.DataSource = dsnew.Tables(0)

    Chart1.Series(

    "Series1").YValueMembers = ("registro,registro") ' "conversion" ')

    Chart1.Series(

    "Series1").XValueMember = "conversion" ' "conversion"

    Chart1.Series(

    "Series1").Palette = ChartColorPalette.EarthTones

     

    ' Chart1.DataBind()

     

    Wednesday, September 01, 2010 4:55 PM