Here is my chart:
ASP.NET code:
<asp:Chart ID="Chart1" runat="server" DataSourceID="SqlDataSource1" Width="752px">
<Series>
<asp:Series Name="Series1" XValueMember="Column2" YValueMembers="Column1">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1" BorderColor="DarkGray">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
How can I show values on blue boxes?
You can do this from your codebehind:
Chart1.Series["Series1"].IsValueShownAsLabel = true;
You can also do this from your ASPX code:
<asp:Chart ID="Chart1" runat="server" DataSourceID="SqlDataSource1" Width="752px">
<Series>
<asp:Series Name="Series1" XValueMember="Column2" YValueMembers="Column1" IsValueShownAsLabel="true">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1" BorderColor="DarkGray">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
Related
I realized that the asp:chart controler was refreshing the page.
For example if I click on a button to display a chart, the current page is refreshed, but I don't want it to be.
Let's say I want to diplay two charts. I have the following code in my default.aspx file (code generated with the toolbox):
<div>
<asp:Chart ID="Chart1" runat="server">
<series>
<asp:Series Name="Series1">
</asp:Series>
</series>
<chartareas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</chartareas>
</asp:Chart>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
<div>
<asp:Chart ID="Chart2" runat="server">
<series>
<asp:Series Name="Series1">
</asp:Series>
</series>
<chartareas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</chartareas>
</asp:Chart>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />
</div>
And the behindcode in the default.aspx.cs file:
protected void Button1_Click(object sender, EventArgs e)
{
double[] yValues = { 71.15, 23.19, 5.66 };
string[] xValues = { "AAA", "BBB", "CCC" };
Chart1.Series["Series1"].Points.DataBindXY(xValues, yValues);
}
protected void Button2_Click(object sender, EventArgs e)
{
double[] yValues = { 71.15, 23.19, 5.66 };
string[] xValues = { "DDD", "EEE", "FFF" };
Chart2.Series["Series1"].Points.DataBindXY(xValues, yValues);
}
My problem is that when I click on the Button1, my first chart appears. But then when I click on the Button2, the first chart disappear and the second one appears.
I would like to keep both charts displayed!
Is it possible? How?
You have 2 buttons on the page, each one firing its own click event. This way, of course you will see just one chart a time.
If you want to see both all the time, do it like this (both buttons pointing to a shared event handler):
<div>
<asp:Chart ID="Chart1" runat="server">
<series>
<asp:Series Name="Series1">
</asp:Series>
</series>
<chartareas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</chartareas>
</asp:Chart>
<asp:Button ID="Button1" runat="server" onclick="ChartButtons_Click" Text="Button" />
</div>
<div>
<asp:Chart ID="Chart2" runat="server">
<series>
<asp:Series Name="Series1">
</asp:Series>
</series>
<chartareas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</chartareas>
</asp:Chart>
<asp:Button ID="Button2" runat="server" onclick="ChartButtons_Click" Text="Button" />
</div>
On your CS file:
protected void ChartButtons_Click(object sender, EventArgs e)
{
double[] yValues = { 71.15, 23.19, 5.66 };
string[] xValues = { "AAA", "BBB", "CCC" };
Chart1.Series["Series1"].Points.DataBindXY(xValues, yValues);
yValues = { 71.15, 23.19, 5.66 };
xValues = { "DDD", "EEE", "FFF" };
Chart2.Series["Series1"].Points.DataBindXY(xValues, yValues);
}
I know how to change the width of the bars using PointWidth which will relatively increase the space between the bars, but I want to keep the same width of the bar while increasing the space between the bars.
<asp:Chart ID="chart" runat="server" Height="300px" Width="850px"
BorderDashStyle="Solid" BorderWidth="2" BackColor="#f0f0f0" Visible="false" EnableViewState="true">
<Legends>
<asp:Legend TitleFont="Microsoft Sans Serif, 8pt, style=Bold" BackColor="Transparent"
Font="Trebuchet MS, 8.25pt, style=Bold" IsTextAutoFit="False" Enabled="False"
Name="Default">
</asp:Legend>
</Legends>
<Series>
<asp:Series Name="s1" Color="#4f81bd" CustomProperties="PointWidth=.6" ChartType="StackedColumn100">
</asp:Series>
<asp:Series Name="s2" Color="#c0504d" CustomProperties="PointWidth=.6" ChartType="StackedColumn100">
</asp:Series>
<asp:Series Name="s3" Color="#9bbb59" CustomProperties="PointWidth=.6" ChartType="StackedColumn100">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1" BorderDashStyle="Solid">
<AxisX>
<LabelStyle Enabled="false" />
<MajorTickMark Enabled="false" />
</AxisX>
<AxisY>
<MajorGrid Interval="10" IntervalOffset="10" />
<MajorTickMark Enabled="true" Interval="10" IntervalOffset="10" />
<LabelStyle Format="{#}%" Interval="10" IntervalOffset="10" />
</AxisY>
<Position Y="0" Height="100" Width="100" X="5"></Position>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
Looks like the space between bars is dynamic and not editable. Changing the width of the chart increases the space between the bars.
How do I hide the white border that appears round the chart using the ASP.NET charting control?
<asp:Chart ID="chtGender" runat="server" BorderSkin-BorderColor="Green" Width="300" Height="350">
<Series>
<asp:Series ChartType="Pie" Palette="EarthTones" ChartArea="MainChartArea">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="MainChartArea" BackColor ="Black" BorderColor = "Black" BorderWidth= "0" Area3DStyle-Enable3D="true">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
I had the same problem and couldnt find a proper solution.
The way I did it was set the borderwidth on the "chartarea" to 20 which overwrote the white border around my pie chart. eg:-
<asp:Chart id="myPieChart" runat="server">
<series>
<asp:Series Name="Series1" ChartType="Pie">
<Points>
<asp:DataPoint YValues="45" />
<asp:DataPoint YValues="34" />
<asp:DataPoint YValues="67" />
</Points>
</asp:Series>
</series>
<chartareas>
<asp:ChartArea Name="ChartArea1"
BackColor="#E6F1FA"
BorderDashStyle="Solid"
BorderWidth="20"
BorderColor="#E6F1FA">
</asp:ChartArea>
</chartareas>
</asp:Chart>
Here's my full markup:
<%#page Title="" Language="VB" MasterPageFile="~/Master Pages/MasterPage.master" AutoEventWireup="false" CodeFile="Statistics.aspx.vb" Inherits="Statistics" %>
<%# Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="phPageContent" runat="Server">
<asp:Label ID="Label1" runat="server" Text="Label" CssClass="CaptionLabel"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" CssClass="DefaultDropDown" />
<asp:Chart ID="Chart1" runat="server" Height="438px" Width="877px" Palette="Bright">
<Series>
<asp:Series ChartArea="ChartArea1" ChartType="Line" Legend="Legend1" Name="Clicks">
</asp:Series>
<asp:Series ChartArea="ChartArea1" ChartType="Line" Legend="Legend1" Name="Conversions">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
<AxisY Title="Count" TitleFont="Microsoft Sans Serif, 10pt">
</AxisY>
<AxisX Title="Month" TitleFont="Microsoft Sans Serif, 10pt">
</AxisX>
<AxisY2 TextOrientation="Rotated270" Title="Commission (USD)" TitleFont="Microsoft Sans Serif, 12pt, style=Bold">
</AxisY2>
</asp:ChartArea>
</ChartAreas>
<Legends>
<asp:Legend Name="Legend1" Title="Legend">
<CellColumns>
<asp:LegendCellColumn Name="Column1" Text="#SERIESNAME">
<Margins Left="15" Right="15" />
</asp:LegendCellColumn>
<asp:LegendCellColumn ColumnType="SeriesSymbol" Name="Column2">
<Margins Left="15" Right="15" />
</asp:LegendCellColumn>
</CellColumns>
</asp:Legend>
</Legends>
<Titles>
<asp:Title Font="Microsoft Sans Serif, 12pt" Name="Title1" Text="Monthly Clicks and Conversions ">
</asp:Title>
</Titles>
</asp:Chart>
</asp:Content>
And here's how it renders. The code behind simply adds the points.
Why does the CHART appear AFTER the label and drop down list control if the label appear first in the flow?
The dropdownlist IS appearing after the chart. If the chart had a border or if you were to add a tag after the dropdown, this will become more obvious.
I have a web application on which there are 2 chart control as follows:
<asp:Chart ID="Chart1" runat="server" DataSourceID="SqlDataSource1"
Height="589px" Width="1109px">
<Series>
<asp:Series Name="Series1" IsValueShownAsLabel="True" LabelAngle="90"
XValueMember="Question" YValueMembers="YesCounter">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
<AxisY Title="Number of Yes">
</AxisY>
<AxisX Title="Questions" IsLabelAutoFit="False">
<LabelStyle Angle="90" Interval="1" />
</AxisX>
<Position Height="94" Width="50" X="3" Y="3" />
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
and
<asp:Chart ID="Chart2" runat="server" DataSourceID="SqlDataSource2"
Height="589px" Width="1109px">
<Series>
<asp:Series Name="Series1" IsValueShownAsLabel="True" LabelAngle="90"
XValueMember="Question" YValueMembers="NoCounter">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
<AxisY Title="Number of No">
</AxisY>
<AxisX Title="Questions" IsLabelAutoFit="False">
<LabelStyle Angle="90" Interval="1" />
</AxisX>
<Position Height="94" Width="50" X="3" Y="3" />
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
Now I want to show one single chart that contains questions on the X-axis and a "yes,no" count on the Y-axis. How this can be done?
You can use stacked bar chart. Something like this http://www.dotnetcharting.com/gallery/view.aspx?id=Gallery/a03