Question

I have Developed a Bubble Chart in Asp.net using a simple sqldatsource by defining x and y axis columns formaly.Now Problem is that the size of bubbles are same for all vlaues.For example the size of bubble for with 100 is same as the size of bubble for 2000 .Please any one tell me if there exist any property or attribute to check the size of bubbles according to the values.I have tried Much to find any property like this but all in vain.Kindly Help me

Update

 <asp:Chart ID="Chart1" runat="server" DataSourceID="SqlDataSource1" 
            Width="1115px" Height="556px" Compression="5">
            <Series>
                <asp:Series Name="Series1" XValueMember="Date" YValueMembers="Amount" 
                    ChartType="Bubble" YValuesPerPoint="2" IsValueShownAsLabel="True" 
                    IsXValueIndexed="True" MarkerSize="0" MarkerStyle="Circle" Palette="EarthTones">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea1" >
                </asp:ChartArea>
            </ChartAreas>
        </asp:Chart>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionStringSMLAPP %>" 
            ProviderName="<%$ ConnectionStrings:ConnectionStringSMLAPP.ProviderName %>" 
            SelectCommand="SELECT DISTINCT to_char(DS_DATE,'DD MON YYYY') &quot;Date&quot;, DS_AMT &quot;Amount&quot;FROM DIESEL where ds_amt &lt; 5000 and DS_DATE in('1-APR-2011','1-DEC-2011') order by 1">
        </asp:SqlDataSource>
Was it helpful?

Solution

As you didn't provide any details how are you initializing series it's hard to give specific answer, but in general chart series has property YValuesPerPoint which should be set to 2 and to the methods series.Points.DataBindXY() or series.Points.AddXY() you can provide multiple Y values. First Y value provided would be responsible for place of bubble on Y axis and second Y value would be for bubble size.

So, to have one bubble in each series you can use following piece of code:

Chart chart = new Chart();
DataTable dt = GetData(); //your method to initialize data table with columns "Series", "X_value", "Y_value" and "BubbleSize_value"

foreach (DataRow row in dt.Rows)
{
    string seriesName = row["Series"].ToString();
    var series = new Series(seriesName);
    series.YValuesPerPoint = 2;
    series.ChartType = SeriesChartType.Bubble;
    series.MarkerStyle = MarkerStyle.Circle;

    series.Points.AddXY(row["X_value"], row["Y_value"], row["BubbleSize_value"]);
    chart.Series.Add(series);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top