Silverlight Visifire Control chart making--silverlight background method drawing

Source: Internet
Author: User
Tags transparent color silverlight

1. Call WCF for information

private void Svc_getsinglechartdatacompleted (object sender, Getsinglechartdatacompletedeventargs e)
{
observablecollection<listitem> Lbaseoilbar = E.result;
Createchart (This.gridvisifire, Lbaseoilbar);
}

2, constructs the chart, according to parses the XML obtains the ListItem drawing

public void Createchart (Grid ogrid, observablecollection<listitem> Lbaseoilbar)
{
foreach (ListItem li in Lbaseoilbar)
{
#regionchart size, frame line, Position
Chart chart = new Mycharts ();
Chart. Width = 800;
Chart. Height = 600;
Chart. scrollingenabled = false;
Chart. Margin = new Thickness (50, 50, 10, 20);
#endregion
#regionset the PlotArea shadow of a chart
PlotArea plot = new PlotArea ();
Plot. shadowenabled = false; Shadow
Chart. PlotArea = plot;
#endregion
#regionChart Title
Title title = new Title ();
String stitle = li. Title;
Title. Text = Stitle;
Title. FontSize = 16;
Chart. Titles.add (title);
#endregion
#regionX Axis
Axis AxisX = new Axis ();
Axislabels xal = new Axislabels
{
FontSize = 14//Setting Text size
};
Axisx.axislabels = Xal;
Axisx.axismaximum = 52;//x Axis Maximum value
Axisx.axisminimum = 1;//x Axis Minimum value
Axisx.interval = 2;//x axis coordinate spacing value
Axisx.intervaltype = Intervaltypes.number;
Chart. Axesx.add (AxisX);
#endregion
#regionY Axis
Axis Axisy = new Axis ();
Axislabels yal = new Axislabels
{
FontSize = 14//Setting Text size
};
Axisy.axislabels = Yal;
if (li. Axisyminimum! = "")
{
Axisy.axisminimum = Convert.todouble (li. axisyminimum);//y axis Minimum value
}
if (li. Axisymaximum! = "")
{
Axisy.axismaximum = Convert.todouble (li. axisymaximum);//y axis Maximum value
}
//y-axis data units
String syuint = li. Yuint;
Axisy.title = Syuint;
axisy.titlefontsize = 15;//Font Size
Axisy.startfromzero = false;//coordinates starting from 0
Axisy.axisminimum = 10; Y-axis Scale minimum value
Axisy.axismaximum = 100; Y-axis scale Max
Chart. Axesy.add (Axisy);
#endregion
#regionDual Axes
String Istwoy = "";
Istwoy = li. Twoy;
if (Istwoy = = "true")
{
Axis Axisyt = new Axis () {Axistype = Axistypes.Secondary};
Axislabels Yalt = new Axislabels
{
FontSize = 14//Setting Text size
};
Axisyt.axislabels = Yalt;
axisyt.valueformatstring = "# #";//Axis data format
if (li. Axisytminimum! = "")
{
Axisyt.axisminimum = Convert.todouble (li. axisytminimum);//y axis Minimum value
}
if (li. Axisytmaximum! = "")
{
Axisyt.axismaximum = Convert.todouble (li. axisytmaximum);//y axis Maximum value
}
Y-Axis data units
String Syuintt = li. Yuintt;
Axisyt.title = Syuintt;
Axisyt.titlefontsize = 15;//Setting Text size
Chart. Axesy.add (AXISYT);
}
#endregion
Title Event
Title. MouseLeftButtonDown + = new Mousebuttoneventhandler (Title_mouseleftbuttondown);

#region Set icon font size
Legend Legend = new Legend ();
Legend. FontSize = 13;//Setting Text size
Chart. Legends.add (legend);
#endregion

X-axis data
string[] Sxlabel = li. Xaxis. ToArray ();

Set the color of a chart
Colorset cs = new Colorset ();
Cs. Id = "Colorset1";

int iMax = 0;
for (int j = 0; J < li. Yaxiss.count (); J + +)
{
YAxis Oyaxis = (YAxis) li. YAXISS[J];
String sytitle = "";
Sytitle = Oyaxis.name;
double[] Dyvalue = null;
Dyvalue = OYAXIS.YValue.ToArray ();
double[] Dyvaluebengin = null;
DataSeries DataSeries = new DataSeries ();
#regionMouse display data style set tilt angle, whether display, coordinate point data style, font size, crude oil production chart special processing, data embedded outside
Dataseries.legendtext = Sytitle;
string[] Dxlabvalue = null;
if (oyaxis.xlabvalue! = null)
{
Dxlabvalue = OYAXIS.XLabValue.ToArray ();
DataSeries.ToolTipText= "#AxisXLabel, #YValue";//mouse Display data format
}
Set coordinate point data tilt angle (-90 to 90)
String labelangle = "";
Labelangle = Oyaxis.labelangle;
if (Oyaxis.labelangle! = "")
{
Dataseries.labelangle = convert.todouble (Labelangle);
}
Whether to display coordinate point data//(True, False)
dataseries.labelenabled = Isshowdata;
Mouse display Data coordinate pointData Styles("##","#,#",".")
DataSeries.yvalueformatstring= "##";
Set icon (mouse display data) font size
Dataseries.labelfontsize = 12;
if (Sxlabel.length > 20)//Figure special treatment
{
Axisx.axislabels.FontSize= 11;//Set Text size
Axisx.axislabels.Angle=-90;
AxisX.Interval= 1;
DataSeries.labelfontsize= 11;//Set icon (mouse display data) font size
}
#regioninline nesting of data
String labelstyle = "";
LabelStyle = Oyaxis.labelstyle;
Switch (LabelStyle)
{
Case "Inside":
Dataseries.labelstyle= Labelstyles.Inside;//Data inline
Break
Case "Outside":
Dataseries.labelstyle = Labelstyles.OutSide;//data is embedded outside
Break
Case "Defaultside":
Break
}
#endregion
#endregion
#regionwhether the axis is a double coordinate
if (Oyaxis.axisytype = = "Secondary")
{
Dataseries.axisytype= Axistypes.Secondary;
}
Else
{
Dataseries.axisytype = Axistypes.Primary;
}
#endregion
#region to set the color of a bar chart
string strcolor = Oyaxis.color;
Switch (Strcolor)
{
Case "Red":
Cs. Brushes.add (New SolidColorBrush (Color.FromArgb (0xFF, 0xFF, 0x45, 0x00)); #FFFF4500 orangered
Break
Case "Yellow":
Cs. Brushes.add (New SolidColorBrush (Color.FromArgb (0xFF, 0xDA, 0xa5, 0x20));//ffdaa520 Goldenrod
Break
Case "Orange":
Cs. Brushes.add (New SolidColorBrush (Colors.orange));
Break
Case "Green":
Cs. Brushes.add (New SolidColorBrush (Colors.green));
Break
Case "Blue":
Cs. Brushes.add (New SolidColorBrush (Color.FromArgb (0xFF, 0x41, 0x69, 0xe1))); Ff4169e1 Royalblue
Break
Case ' white ':
Cs. Brushes.add (New SolidColorBrush (Color.FromArgb (0xFF, 0xFF, 0xFF, 0xff))); FFFFFFFF royalblue Color.FromArgb (0xFF, 0xFF, 0xFF, 0xff) transparent color; 00ff00ff
Break
Case "Comflowerblue":
Cs. Brushes.add (New SolidColorBrush (Color.FromArgb (0xFF, 0x64, 0x95, 0xed))); Ff6495ed Comflowerblue
Break
Case "indianred":
Cs. Brushes.add (New SolidColorBrush (Color.FromArgb (0xFF, 0xCD, 0x5c, 0x5c))); FFCD5C5C indianred
Break
Case "Slateblue":
Cs. Brushes.add (New SolidColorBrush (Color.FromArgb (0xFF, 0x6a, 0x5a, 0xCD))); //
Break
Case "Palegreen":
Cs. Brushes.add (New SolidColorBrush (Color.FromArgb (0xFF, 0x98, 0XFB, 0x98))); //
Break
Case "Yellowgreen":
Cs. Brushes.add (New SolidColorBrush (Color.FromArgb (0xFF, 0x9a, 0xCD, 0x32))); //
Break
Case "orangered":
Cs. Brushes.add (New SolidColorBrush (Color.FromArgb (0xFF, 0xFF, 0x00, 0x00)); #FFFF0000 Red
Break
Case "Darkgreen":
Cs. Brushes.add (New SolidColorBrush (Color.FromArgb (0xFF, 0x00, 0x80, 0x00));//green
Break
Default
Break
}
#endregion
#regionChart Type(Columnar, pie-like ...) )
String scharttype = li. ChartType;
Renderas Orenderas = new Renderas ();
Switch (scharttype)
{
Case "Column":
Orenderas = Renderas.column;
#regionColumn WidthSelf-adapting
if (li. Datapointwidth! = "")
//{
Chart. Datapointwidth = Convert.todouble (li. Datapointwidth);//Set Fixed width
//}
if (Sxlabel.length < 10)
{
Chart. Datapointwidth= 6;
}
Else
{
Chart. Datapointwidth = chart. Width * 0.08/SXLABEL.LENGTH;
}
#endregion
Break
Case "Pie":
Orenderas = Renderas.pie;
Dataseries.labelfontsize = 14;//Set icon font size
Dataseries.labelenabled = true; displaying coordinate point data
Break
Case ' line ':
Orenderas = Renderas.line;
Break
Case ' area ':
Orenderas = Renderas.area;
if (J > 0)
{
YAxis Oyaxisbengin = (YAxis) li. Yaxiss[0];
Dyvaluebengin = OYAXISBengin.YValue.ToArray ();
}
Break
}
Dataseries.renderas= Orenderas;
#endregion
#region Construction Data Y-axis coordinate maximum setting
Datapoint DP;
if (Sxlabel! = null)
{
//Maximum value
int Max = 0;
Max = (int) dyvalue[0];
for (int i = 0; i < sxlabel.length; i++)
{
//Maximum value
max = max > (int) dyvalue[i]? Max: (int) dyvalue[i];

DP = new Datapoint ();
Dp. Axisxlabel = Sxlabel[i];
Dp. Yvalue = Dyvalue[i];
DATASERIES.DATAPOINTS.ADD (DP);

}
#region Maximum Value
if (j = = 0)
{
IMax = Max;
}
Else
{
IMAX = IMAX > Max? Imax:max;
}
#endregion
}
#endregion
Chart. Series.add (dataSeries);
}
#regionMaximum setting Y-axis iconSolve the whole problem of mouse display data
Double yaxismaximum = Math.Round ((imax/0.85), 0);
int len = yaxismaximum.tostring (). Length;
String lasts = "";
if (Len > 2)
{
for (int m = 0; m < len-2; m++)
{
Lasts + = "0";
}
Yaxismaximum = Convert.ToInt32 ((Convert.ToInt32 () (Yaxismaximum.tostring (). Substring (0, 2)) + 1). ToString () + lasts);
Axisy.axismaximum= Yaxismaximum;
}
#endregion
#region set Chart to use the customColor CollectionColorset1
if (CS. Brushes.count > 0)
{
Chart. Colorsets.clear ();
Chart. Colorsets.add (CS);
Chart. Colorset = "Colorset1";
}
# endregion

OGRID.CHILDREN.ADD (chart);
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.