Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a requirement that I need to add image to x-axis custom label. when user clicked on that Image I have to show a popup. I already have a text on x-axis but i want image too along with that text.

Any suggestions is appreciated.

What I have tried:

try
          {
              DataTable pcharttable = dataset.PrjSumTable;
              if (pcharttable.Rows.Count > 0)//(pcharttable.Rows.Count > 0 && comboAssignedto.SelectedValue.ToString() != "All")
              {
                  if (strassignto == "'All'" || strassignto == "All")
                  {
                      pcharttable.DefaultView.RowFilter = "Assignedto like '" + "%" + "'";
                      pcharttable.DefaultView.Sort = strsort + " ASC";
                      pcharttable = pcharttable.DefaultView.ToTable();
                  }
                  else
                  {
                      pcharttable.DefaultView.RowFilter = "Assignedto in (" + strassignto + ")";
                      pcharttable.DefaultView.Sort = strsort + " ASC";
                      pcharttable = pcharttable.DefaultView.ToTable();
                  }

                  prjchart.Series[0].Points.DataBind(pcharttable.DefaultView, "id", "overdue", null);
                  prjchart.Series[1].Points.DataBind(pcharttable.DefaultView, "id", "current", null);
                  prjchart.Series[2].Points.DataBind(pcharttable.DefaultView, "id", "notyetdue", null);
                  prjchart.Series[3].Points.DataBind(pcharttable.DefaultView, "id", "complete", null);

                  //'Show All Categories on RHS axis
                  prjchart.ChartAreas[0].AxisX.Interval = 1;
                  prjchart.ChartAreas[0].AxisX.LabelAutoFitStyle = LabelAutoFitStyles.DecreaseFont;

                  prjchart.ChartAreas[0].AxisY.Minimum = 0;
                  prjchart.ChartAreas[0].AxisY.Maximum = 100;
                  prjchart.ChartAreas[0].AxisY.Interval = 10;
                  prjchart.ChartAreas[0].AxisY.LabelStyle.Format = "{0}%";
                  prjchart.ChartAreas[0].AxisY.Title = "Tasks";
                  prjchart.ChartAreas[0].AxisY.TitleAlignment = StringAlignment.Center;
                  prjchart.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("Microsoft Sans Serif", 12);

                  prjchart.ChartAreas[0].AxisX.Title = "Project";
                  prjchart.ChartAreas[0].AxisX.TitleAlignment = StringAlignment.Center;
                  prjchart.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("Microsoft Sans Serif", 12);
                  prjchart.ChartAreas[0].AxisX.Minimum = 0;
                  prjchart.ChartAreas[0].AxisX.Maximum = pcharttable.Rows.Count;
                      prjchart.ChartAreas[0].AxisX.ScrollBar.Enabled = true;
                      prjchart.ChartAreas[0].AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;
                      prjchart.ChartAreas[0].AxisX.ScrollBar.ButtonColor = System.Drawing.Color.LightGray;
                      prjchart.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
                      prjchart.ChartAreas[0].AxisX.ScaleView.Size = 15;
                      prjchart.ChartAreas[0].AxisX.ScaleView.MinSizeType = DateTimeIntervalType.Number;
                      prjchart.ChartAreas[0].AxisX.ScaleView.Position =  prjchart.ChartAreas[0].AxisX.Minimum;
                  if (prjchart.ChartAreas[0].AxisX.Maximum< 15)
                  {

                      prjchart.ChartAreas[0].AxisX.ScaleView.Scroll(ScrollType.First);
                  }

                  prjchart.ChartAreas[0].AxisX.ScaleView.Zoomable = false;


                  foreach (Series s in prjchart.Series)
                  {
                  foreach (DataPoint p in s.Points)
                  {
                      if (p.YValues.Length > 0 && (double)p.YValues.GetValue(0) == 0)
                      {
                          p.IsValueShownAsLabel = false;
                      }
                      else
                      {
                          p.IsValueShownAsLabel = true;
                          p.Label = "#VALY";
                      }
                  }

              }

              //remove y axis lines
              prjchart.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.NotSet;//System.Windows.Forms.DataVisualization.Charting.
                  //ChartArea CA = prjchart.ChartAreas[0];
                  //CA.Position = new ElementPosition(0, 0, 100, 100);                                                                          //'Move legend to bottom and center
                  prjchart.Legends[0].Docking = Docking.Top;
              prjchart.Legends[0].Alignment = StringAlignment.Center;

              for (int i = 1; i < 4; i++)
              {
                  prjchart.Legends[0].CustomItems[i].Cells[0].ImageTransparentColor = Color.Red;
              }
              // Set tag property for all custom items to appropriate series
              prjchart.Legends[0].CustomItems[0].Tag = prjchart.Series[0];
              prjchart.Legends[0].CustomItems[1].Tag = prjchart.Series[1];
              prjchart.Legends[0].CustomItems[2].Tag = prjchart.Series[2];
              prjchart.Legends[0].CustomItems[3].Tag = prjchart.Series[3];
              prjchart.Titles.Clear();
              prjchart.Titles.Add("Dashboard - Project");
          }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900