如何动态添加图表中的系列?需要参考!! [英] HOW TO ADD SERIES IN CHART DYNAMICALLY ? NEED REFERENCES !!
本文介绍了如何动态添加图表中的系列?需要参考!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
前端(根据存储过程中的动态upadte,我还要在首页上还有什么)
---------- -------------------------------------------------- -------------------------------------------------- ------------------------------
Front end( what else i have to right in the front page according to dynamic upadte from stored procedure )
--------------------------------------------------------------------------------------------------------------------------------------------
<asp:Chart ID="chtCampaignHits" runat="server" BackColor="76, 125, 126"
BorderDashStyle="Solid" BackSecondaryColor="White" BackGradientStyle="DiagonalLeft"
BorderWidth="2px" BorderColor="#1A3B69">
<BorderSkin SkinStyle="Emboss" />
<ChartAreas>
<asp:ChartArea Name="MainChartArea" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid"
BackSecondaryColor="White" BackColor="64, 165, 191, 228" ShadowColor="Transparent"
BackGradientStyle="TopBottom">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
.CS FILE (DYNAMIC UPDATE FROM STORED PROCEDURE)
-------------------------------------------------------------
if (dt.Rows.Count != 0)
{
//var v = (from row in dt.AsEnumerable()
// select row.Field<Int64>("Campaigntitle").ToString()).Distinct<string>(); priviouly this code
var v = (from Rows in dt.AsEnumerable()
select Rows.Field<string>("Campaigntitle").ToString()).Distinct<string>();
foreach (string s in v)
{
Console.WriteLine(s);
foreach (DataRow row in dt.Rows)
{
if (row.HasErrors)
{
Console.WriteLine(row.RowError);
}
}
// SHOULD I USE ROWFILTER OR ITS OPTIONAL.
dt.DefaultView.RowFilter = "count=" + s; //TILL THIS THE CODE RUNNING FIND. WHEN COMES TO ADD SERIES IN GOING TO CATCH EXCEPTION. NEED YOUR HELP !!
chtCampaignHits.Series[s].Enabled = true;
chtCampaignHits.Series.Add(new Series(s));
chtCampaignHits.Series[s].Label = s;
chtCampaignHits.Series[s].ChartArea = "MainChartArea";
chtCampaignHits.Series[s].ChartType = SeriesChartType.Line; //priviously chat was SeriesChartType.Spline;
chtCampaignHits.Series[s].BorderWidth = 3;
//this was above priviouly
chtCampaignHits.Series[s].Points.DataBindXY(dt.DefaultView, "Campaigntitle", dt.DefaultView, "hits");
}
chtCampaignHits.Legends.Add("Legend1");
chtCampaignHits.Legends["Legend1"].Enabled = true;
//chtCampaignHits.Legends["Legend1"].Alignment = System.Drawing.StringAlignment.Near;
chtCampaignHits.Legends["Legend1"].LegendStyle = LegendStyle.Row;
chtCampaignHits.Legends["Legend1"].Docking = Docking.Bottom;
chtCampaignHits.Legends["Legend1"].BackColor = System.Drawing.Color.FromName("#4C7D7E");
chtCampaignHits.Legends["Legend1"].BackGradientStyle = GradientStyle.DiagonalLeft;
}
}
catch (Exception)
{
Response.Write("Error in FillChartInfo");
}
推荐答案
您正在尝试启用系列,然后将其添加到图表中
Move行
You are trying to enable a series before adding it to chart
Move the line
chtCampaignHits.Series[s].Enabled = true;
next to
chtCampaignHits.Series.Add(new Series(s));
您的代码应为
Your code should be
chtCampaignHits.Series.Add(new Series(s));
chtCampaignHits.Series[s].Enabled = true;
chtCampaignHits.Series[s].Label = s;
更新回答
Updated answer
Your code should be
chtCampaignHits.Series.Add(s);
chtCampaignHits.Series[s].Enabled = true;
chtCampaignHits.Series[s].Label = s;
这篇关于如何动态添加图表中的系列?需要参考!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文