Initialize and generate a Stacked column chart. Click a different stacked part to display the details of this part. Use a column chart. Click the bar chart to continue displaying details. Use a pie chart. The effect of transparency switching from 0 to 1. Back button to return to the previous chart.
XAML:
<Usercontrol X: class = "Simple. Page"
Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
Width = "800" Height = "640">
<Grid X: Name = "layoutroot" background = "white">
<Grid. Resources>
<Storyboard X: Name = "storyboard">
<Doubleanimation X: Name = "storyboardda" from = "1" to = "0"
Storyboard. targetname = "chartpanel" storyboard. targetproperty = "uielement. Opacity"
Autoreverse = "false" Duration = "0: 0: 1">
</Doubleanimation>
</Storyboard>
</Grid. Resources>
<Stackpanel>
<Grid X: Name = "chartpanel" Height = "600" width = "800">
</GRID>
<Button X: Name = "btn_back" width = "100" Height = "40" content = "back" Click = "btn_back_click"> </button>
</Stackpanel>
</GRID>
</Usercontrol>
CS:
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. net;
Using system. windows;
Using system. Windows. controls;
Using system. Windows. documents;
Using system. Windows. input;
Using system. Windows. Media;
Using system. Windows. Media. animation;
Using system. Windows. shapes;
Using visifire. charts;
Using visifire. commons;
Namespace simple
{
Public partial class page: usercontrol
{
Public page ()
{
Initializecomponent ();
// Create a new visifire chart
Createchart ();
}
/// <Summary>
/// Function to create a chart
/// </Summary>
Public void createchart ()
{
Chart chart = new chart ();
Chart. view3d = true;
Charts. width = 800;
Chart. Height = 600;
Title = new title ();
Title. Text = "SL chart Demo ";
Chart. Titles. Add (title );
For (int c = 0; C <3; C ++)
{
Dataseries = new dataseries ();
Dataseries. renderas = renderas. stackedcolumn;
Dataseries. legendtext = C. tostring ();
Datapoint;
For (INT I = 0; I <5; I ++)
{
Datapoint = new datapoint ();
Datapoint. yvalue = Rand. Next (1, 10,100 );
Datapoint. mouseleftbuttondown + = new mousebuttoneventhandler (datapoint_mouseleftbuttondown );
Dataseries. datapoints. Add (datapoint );
}
Chart. Series. Add (dataseries );
}
This. chartpanel. Children. Add (Chart );
This. currentsetp = 1;
}
Void datapoint_mouseleftbuttondown (Object sender, mousebuttoneventargs E)
{
This. hidedispaly ();
This. chartpanel. Children. Clear ();
This. createcreatecolumnchart ();
}
Void datapoint_mouseleftbuttondowncolumnchart (Object sender, mousebuttoneventargs E)
{
This. hidedispaly ();
This. chartpanel. Children. Clear ();
This. createcreatepiechart ();
}
Private void createcreatepiechart ()
{
Chart chart = new chart ();
Chart. view3d = true;
Charts. width = 800;
Chart. Height = 600;
Title = new title ();
Title. Text = "SL chart Demo ";
Chart. Titles. Add (title );
Dataseries = new dataseries ();
Dataseries. renderas = renderas. Pie;
Dataseries. legendtext = "";
Datapoint;
For (INT I = 0; I <5; I ++)
{
Datapoint = new datapoint ();
Datapoint. yvalue = Rand. Next (1, 10,100 );
Dataseries. datapoints. Add (datapoint );
}
Chart. Series. Add (dataseries );
This. chartpanel. Children. Add (Chart );
This. currentsetp = 3;
}
Private void createcreatecolumnchart ()
{
Chart chart = new chart ();
Chart. view3d = true;
Charts. width = 800;
Chart. Height = 600;
Title = new title ();
Title. Text = "SL chart Demo ";
Chart. Titles. Add (title );
Dataseries = new dataseries ();
Dataseries. renderas = renderas. column;
Dataseries. legendtext = "";
Datapoint;
For (INT I = 0; I <5; I ++)
{
Datapoint = new datapoint ();
Datapoint. yvalue = Rand. Next (1, 10,100 );
Datapoint. mouseleftbuttondown + = new mousebuttoneventhandler (datapoint_mouseleftbuttondowncolumnchart );
Dataseries. datapoints. Add (datapoint );
}
Chart. Series. Add (dataseries );
This. chartpanel. Children. Add (Chart );
This. currentsetp = 2;
}
/// <Summary>
/// Create a random class variable
/// </Summary>
Random Rand = new random (datetime. Now. millisecond );
Private int currentsetp = 0;
Private void gostep (INT currentstep)
{
If (currentstep = 1)
{
Return;
}
If (currentstep = 2)
{
This. chartpanel. Children. Clear ();
This. createchart ();
}
If (currentstep = 3)
{
This. chartpanel. Children. Clear ();
This. createcreatecolumnchart ();
}
}
Private void btn_back_click (Object sender, routedeventargs E)
{
This. gostep (currentsetp );
This. hidedispaly ();
}
Private void hidedispaly ()
{
This. storyboardda. From = 0;
This. storyboardda. To = 1;
This. storyboard. Begin ();
}
}
}