Открытие нового окна из элемента управления графиком asp.net - PullRequest
3 голосов
/ 22 сентября 2011

Я запускаю команду JS window.open из элемента управления диаграммы asp.net, но она не запускается.

Ниже приведен код страницы .aspx, которая будет строить пирамиду.

<div>

        <asp:Chart ID="Chart1" runat="server" Height="416px" ImageType="Jpeg" 
        Width="525px" IsMapAreaAttributesEncoded="True" Palette="None" 
        PaletteCustomColors="Navy; DarkBlue; DarkBlue; DarkBlue; DarkBlue; DarkBlue; DarkBlue" 
        TextAntiAliasingQuality="SystemDefault" ImageStorageMode="UseImageLocation">
        <Series>
            <asp:Series BackGradientStyle="DiagonalRight" BackSecondaryColor="Black" 
                BorderColor="Black" ChartType="Pyramid" Color="Transparent" 
                CustomProperties="Pyramid3DRotationAngle=8, PyramidMinPointHeight=60, PyramidPointGap=3, PyramidLabelStyle=Inside" 
                Font="Verdana, 8pt, style=Bold" IsValueShownAsLabel="True" Name="Series1" 
                ShadowColor="Black" LabelForeColor="White" Palette="Grayscale">
                <Points>
                    <asp:DataPoint CustomProperties="PyramidInsideLabelAlignment=Top" 
                        Label="             xxxxxx                               Column-1"
                        ToolTip="1111" YValues="40"/>
                    <asp:DataPoint CustomProperties="PyramidInsideLabelAlignment=Top" 
                        Label="xxxxxx                         Column-2" MapAreaAttributes="" ToolTip="2222"
                        YValues="40" />
                    <asp:DataPoint CustomProperties="PyramidInsideLabelAlignment=Top" 
                        Label="xxxxxx                   Column-3" MapAreaAttributes="" ToolTip="" Url="" 
                        YValues="40" />
                    <asp:DataPoint CustomProperties="PyramidInsideLabelAlignment=Top" 
                        Label="     xxxxxx              Col4" MapAreaAttributes="" ToolTip="" Url="" 
                        YValues="40"  />
                    <asp:DataPoint 
                        Label="  xxxxxx          Col5" MapAreaAttributes="" ToolTip="" Url="" 
                        YValues="40"  />
                    <asp:DataPoint Label="  xxxxxx    Col6" MapAreaAttributes="onClick='javascript:OpenPage();'" ToolTip="" Url="" 
                        YValues="40" />
                    <asp:DataPoint CustomProperties="PyramidInsideLabelAlignment=Bottom" 
                        Label="xx Col7" MapAreaAttributes="" ToolTip="" Url="" YValues="40" />
                </Points>
            </asp:Series>
        </Series>
        <ChartAreas>
            <asp:ChartArea Name="ChartArea1">
                <Area3DStyle Enable3D="True" IsRightAngleAxes="False" Perspective="30" 
                    Inclination="45" PointGapDepth="1000" Rotation="60" />
            </asp:ChartArea>
        </ChartAreas>
    </asp:Chart>    

    </div>

Ниже приведен код позади;

protected void Page_Load(object sender, EventArgs e)
        {
            string statusClicked = string.Empty;
            Series series = new Series("MySeries");
            series.ChartType = SeriesChartType.Pyramid;
            series.BorderWidth = 3;

            DataTable dt = new DataTable();

            dt.Columns.Add("Column-1", typeof(int));
            dt.Columns.Add("Column-2", typeof(int));
            dt.Columns.Add("Column-3.", typeof(int));
            dt.Columns.Add("Column-4", typeof(int));
            dt.Columns.Add("Column-5", typeof(int));
            dt.Columns.Add("Column-6", typeof(int));
            dt.Columns.Add("Column-7", typeof(int));

            dt.Rows.Add(1400, 2240, 7660, 3410, 15, 4, 9);
            int colCount = dt.Columns.Count;
            List<string> xaxis = new List<string>();
            List<double> yaxis = new List<double>();

          Chart1.Series[0].Points[0].MapAreaAttributes = "onclick=\"javascript:window.open('http://www.google.com');\"";

         }

В идеале, при щелчке любой серии на графике должна открываться ссылка на Google, и присвоенный статус будет соответствовать полученному из кода.Но код никогда не работает.

URL-адрес, который он открывает, выглядит примерно так:

http://localhost:1450/javascript%3avar+win%3dwindow.open('http%3a%2f%2fwww.google.com%3fstatus%3dTestStatus')%3b

здесь, поскольку вы можете видеть, что статус имеет статус теста, и поэтому ссылка, которая должна открыться, http://www.google.com/?status=TestStatus

ПРИМЕЧАНИЕ: свойство labelURL будет принимать только URL.

1 Ответ

0 голосов
/ 22 сентября 2011

Не проверено, но вы можете использовать атрибуты MapArea. Что-то вроде;

Chart1.Series[0].Points[i].LabelUrl = "http://www.google.co.in?status=" + dt.Columns[i].ColumnName.ToString();
series.MapAreaAttributes = "target=\"_blank\"";

или вы можете сделать что-то вроде (без строки запроса);

        foreach (Series series in Chart1.Series)
        {
            series.MapAreaAttributes = "onclick=\"javascript:window.open('http://www.google.com');\"";
        }    

Здесь - дополнительная информация о ключевых словах, которые могут помочь с передачей параметров строки запроса.

В вашем случае вы также можете использовать MapAreaAttributes для DataPointCollection

Chart1.Series[0].Points[i].MapAreaAttributes = "onclick=\"javascript:window.open('http://www.google.co.in?status=" + dtSample.Columns[4].ColumnName.ToString() + "');\"";
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...