简体   繁体   English

在Razor for Asp.Net中,每当我创建图表时,它就会自动全屏显示并占据完整视图

[英]In Razor for Asp.Net Whenever I create a chart it automatically is full screen and takes up the full view

I've tried making the size of the chart smaller but it still takes up the full screen. 我试图缩小图表的大小,但仍然占据全屏。 I've also tried putting it in a div and setting the height and width that way.` 我还尝试将其放在div中,并以此方式设置高度和宽度。

<div style="height=400; width=600;">
    @{
        var MyChart = new Chart(600, 400)
            .AddTitle("File Count")
            .AddSeries(
                name: "File Count",
                chartType: "bar",
                xValue: descList.ToArray(),
                yValues: intList.ToArray());
        MyChart.Write();
    }
</div>

` `

I would do this by creating a CSS class which sets the width and height of the child tag that gets generated by the Chart.Write() method. 我将通过创建一个CSS类来实现此目的,该类设置由Chart.Write()方法生成的子标记的宽度和高度。

CSS 的CSS

.chart-container img {
    width: 600px;
    height: 400px;
}

HTML 的HTML

<div class="chart-container">
    @{
        var MyChart = new Chart(600, 400)
            .AddTitle("File Count")
            .AddSeries(
                name: "File Count",
                chartType: "bar",
                xValue: descList.ToArray(),
                yValues: intList.ToArray());
        MyChart.Write();
    }
</div>

I know this question is really old, but I just struggled with the same issue myself. 我知道这个问题确实很老,但是我自己也为同一个问题而苦恼。

For other newbies like myself, this might be worth something. 对于像我这样的其他新手,这可能是值得的。

The MyChart.Write() basically produces an image and returns that to your browser regardles of the surrounding razor code. MyChart.Write()基本上会生成一个图像,并将其返回给浏览器,使其与周围的剃刀代码相关。

You can also see the title of your browser shows something like "Image (400x600)". 您还可以看到浏览器的标题显示类似“图像(400x600)”的内容。 The browser is displaying an image, not a web page. 浏览器正在显示图像,而不是网页。

In order to show the rendered chart as part of a web page, you have to build your web page and place an <img> tag where the source of the image is a separate view like rendermage.cshtml where you place your code from the question. 为了将呈现的图表显示为网页的一部分,您必须构建网页并放置<img>标记,其中图像源是单独的视图(例如rendermage.cshtml),在其中放置问题代码。

I got my info from here: Displaying Charts Inside a Web Page 我从这里获取信息: 在网页内显示图表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM