Showing posts with label asp.net pie chart with legends. Show all posts
Showing posts with label asp.net pie chart with legends. Show all posts

Wednesday, June 18, 2014

ASP.NET Pie Chart with Random Number Generation Using ADO.NET Alog With Tooltip, Percentage and Legends







<tr>
  <td align="right">
    Charttype
  </td>
  <td>
    <asp:DropDownListID="ddlChartType"runat="server"></asp:DropDownList>
  </td>
</tr>

protected override void OnLoad(EventArgs e)
{
     base.OnLoad(e);
     if (!IsPostBack)
     {
          // bind chart type names to ddl
          ddlChartType.DataSource = Enum.GetNames(typeof(SeriesChartType));
          ddlChartType.DataBind();
     }
     DataBind();
}







<tr>
     <td align="right">
          Days
     </td>
     <td>
          <asp:DropDownListID="ddlDays"runat="server">
               <asp:ListItemText="10Days"Value="10"Selected="True"></asp:ListItem>
               <asp:ListItemText="20Days"Value="20"></asp:ListItem>
               <asp:ListItemText="30Days"Value="30"></asp:ListItem>
               <asp:ListItemText="40Days"Value="40"></asp:ListItem>
               <asp:ListItemText="50Days"Value="50"></asp:ListItem>
          </asp:DropDownList>
     </td>
</tr>




<tr>
    <td align="right">
        3D Settings
    </td>
     <td>
        <asp:CheckBoxID="cbUse3D"runat="server"Text="Use3DChart"/>
     </td>
</tr>




<tr>
     <td colspan="2">
          <asp:ButtonID="btnGetPOResults"runat="server"Text="Result" onclick="btnGetPOResults_Click"/>
     </td>
</tr>

protectedvoidbtnGetPOResults_Click(objectsender,EventArgse)
{
 ShowChart();
}
 
private void ShowChart()
{
 //definetestdata
 #regionByHashTable
 //Dictionary<DateTime,int>testData=newDictionary<DateTime,int>();
  
 //Randomrnd=newRandom(Guid.NewGuid().GetHashCode());
 //for(inti=0;i<3;i++)
 //{
 //testData.Add(DateTime.Now.AddDays(i),rnd.Next(1,50));
 //}
 //chartPOValidationStatus.Series["Testing"].Points.DataBind(testData,"Key","Value",string.Empty);
 
 //chartPOValidationStatus.Series["Testing"].Points[0].Color=Color.Green;
 //chartPOValidationStatus.Series["Testing"].Points[1].Color=Color.Red;
 //chartPOValidationStatus.Series["Testing"].Points[2].Color=Color.Blue;
 
 #endregion
 
 #regionByDataTable
 
 Randomrnd=newRandom(Guid.NewGuid().GetHashCode());
 vartable=newDataTable();
 
 table.Columns.Add("Status",typeof(string));
 table.Columns.Add("TotalJobs",typeof(long));
 
 varrow=table.NewRow();
 row["Status"]="Passed";
 row["TotalJobs"]=rnd.Next(1,50);;
 table.Rows.Add(row);
 
 row=table.NewRow();
 row["Status"]="Failed";
 row["TotalJobs"]=rnd.Next(1,50);;
 table.Rows.Add(row);
 
 row=table.NewRow();
 row["Status"]="NotVarifid";
 row["TotalJobs"]=rnd.Next(1,50);;
 table.Rows.Add(row);
 
 chartPOValidationStatus.DataSource=table;
 chartPOValidationStatus.DataBind();
 #endregion
  
 //Properties
 chartPOValidationStatus.Series["Testing"].XValueMember="Status";
 chartPOValidationStatus.Series["Testing"].YValueMembers="TotalJobs";
 chartPOValidationStatus.Series["Testing"].ChartTypeName=ddlChartType.SelectedValue;
 chartPOValidationStatus.Series["Testing"].IsValueShownAsLabel=true;
 chartPOValidationStatus.Series["Testing"].IsVisibleInLegend=true;
 
 //chartPOValidationStatus.Series["Testing"].Label="#PERCENT{P2}";
 //chartPOValidationStatus.Series["Testing"].LegendText="#VALX";
 
 chartPOValidationStatus.Series["Testing"].ToolTip="#VAL";
 chartPOValidationStatus.Series["Testing"].Label="#VAL";
 chartPOValidationStatus.Series["Testing"].LegendText="#VALX"+"("+"#PERCENT{P1}"+")";
 
 chartPOValidationStatus.ChartAreas[0].Area3DStyle.Enable3D=cbUse3D.Checked;
 chartPOValidationStatus.ChartAreas[0].Area3DStyle.Inclination=Convert.ToInt32(0);
}

















<asp:ChartID="chartPOValidationStatus"runat="server"Height="400px"Width="800px"BackColor="Transparent">
     <legends>
        <asp:LegendAlignment="Center"Docking="Bottom"IsTextAutoFit="False"Name="Default"LegendStyle="Row"/>
     </legends>
     <Series>
        <asp:SeriesName="Testing"IsValueShownAsLabel="true"IsVisibleInLegend="true"IsXValueIndexed="true">
         </asp:Series>
      </Series>
      <ChartAreas>
         <asp:ChartAreaName="chartAreaPOValidations">
          <Area3DStyle/>
         </asp:ChartArea>
       </ChartAreas>
</asp:Chart>