WebMatrix - Creating 3D Charts
This post provides details and code about creating 3D charts in WebMatrix (Beta).
A quick method for creating 3D charts using ASP.NET Web Pages is to use the built in theme named Vanilla3D. However, if you need to create a custom 3D chart, you can add an Area3DStyle node to a template and set a few values (shown below). This post is based on the WebMatrix Chapter 7 - Displaying Data in a Chart. It may be helpful to complete the steps in Chapter 7 or download the related WebMatrix samples.
At the root of your web site, create a new XML file named OrangeBlue3DTemplate.xml.
Replace the default XML in the file with the following:
Code Snippet- <Chart Palette="BrightPastel"
- BackColor="#D3DFF0"
- BackGradientStyle="TopBottom"
- BackSecondaryColor="White"
- BorderColor="26, 59, 105"
- BorderWidth="2"
- BorderlineDashStyle="Solid">
- <Series>
- <series _Template_="All"
- BorderColor="180, 26, 59, 105"
- CustomProperties="LabelStyle=Bottom"
- IsValueShownAsLabel="False">
- </series>
- </Series>
- <ChartAreas>
- <ChartArea _Template_="All"
- BackColor="Orange"
- BackGradientStyle="TopBottom"
- BackSecondaryColor="White"
- ShadowColor="Transparent"
- BorderColor="64, 64, 64, 64"
- BorderDashStyle="Solid">
- <Area3DStyle Enable3D="True"
- Inclination="5">
- </Area3DStyle>
- <AxisX ArrowStyle="Triangle"
- IsLabelAutoFit="False"
- LineColor="64, 64, 64, 64">
- <MajorGrid LineColor="64, 64, 64, 64" />
- <LabelStyle Font="Trebuchet MS, 10pt, style=Bold"
- IsStaggered="True" />
- </AxisX>
- </ChartArea>
- </ChartAreas>
- <Titles>
- <Title _Template_="All"
- Font="Trebuchet MS, 14.25pt, style=Bold"
- ForeColor="26, 59, 105"
- ShadowOffset="3"
- ShadowColor="32, 0, 0, 0">
- </Title>
- </Titles>
- <BorderSkin SkinStyle="Emboss" />
- </Chart>
Notice that the new XML includes the 3D style:
Code Snippet- <Area3DStyle Enable3D="True"
- Inclination="5">
- </Area3DStyle>
At the root of your website, create a new file named ChartWith3DTemplate.cshtml.
Replace the default markup in the page with the following:
Code Snippet- @{
- var key = new Chart(width: 600,
- height: 400,
- templatePath: "OrangeBlue3DTemplate.xml")
- .AddTitle("Chart Title")
- .AddSeries(
- name: "Employee",
- xValue: new[] { "Peter", "Andrew", "Julie", "Mary", "Dave" },
- yValues: new[] { "2", "6", "4", "5", "3" })
- .Write();
- }
Run the ChartWith3DTemplate.cshtml page in a browser.
For more information about 3D charts, see 3D Charts (Chart Controls) and the ChartArea3DStyle Class on MSDN. These two links will provide the information you need to completely customize your 3D charts in WebMatrix.
-- Erik Reitan
Web Platform and Tools Developer Content
This posting is provided "AS IS" with no warranties, and confers no rights.