Hi Team,
Please find the below which i have used to display pie chart.
@{
ViewBag.Title = "Report";
Layout = "~/Views/Common/_BaseContent.cshtml";
var X = Html.X();
}
@section headtag
{
<script type="text/javascript">
var tipRenderer = function (storeItem, item) {
//calculate percentage.
var total = 0;
App.ReportsPieChart.getStore().each(function (rec) {
total += rec.get('TestcaseCount');
});
this.setTitle(storeItem.get('Name') + ': ' + Math.round(storeItem.get('TestcaseCount') / total * 100) + '%');
}
</script>
}
@{
//pie chart related fields
var pieChartTip = X.ChartTip()
.TrackMouse(true)
.Width(180)
.Height(28)
.Renderer(r => r.Fn = "tipRenderer");
var pieChartSeriesLabel = X.SeriesLabel()
.Field(new[] { "Name" })
.Font("18px Arial")
.Orientation(Ext.Net.Orientation.Vertical);
var nameModelField = X.ModelField().Name("Name");
var testcaseCountModelField = X.ModelField().Name("TestcaseCount");
var pieChartFieldsModel = X.Model()
.Fields(nameModelField,
testcaseCountModelField);
var pieChartData = new object[]
{
new{
Name= "Passed Test cases",
TestcaseCount =4
},
new{
Name= "Failed Test cases",
TestcaseCount = 6
}
};
var pieChartStore = X.Store()
.Data(Model)
.Model(pieChartFieldsModel)
.Data(pieChartData);
var pieChartSeries = X.PieSeries()
.AngleField("TestcaseCount")
.ShowInLegend(true)
.Donut(0)
.Label(pieChartSeriesLabel)
.Tips(pieChartTip)
.ColorSet(new string [] {"Green","Red"});
Ext.Net.Chart reportsPieChart = X.Chart()
.ID("ReportsPieChart")
.Animate(true)
.AutoShow(true)
.Shadow(true)
.InsetPadding(60)
.LegendConfig(X.ChartLegend().Position(Ext.Net.LegendPosition.Right))
.StyleSpec("background:#fff;")
.Store(pieChartStore)
.Series(pieChartSeries);
var pieChartPanel = X.Panel()
//.Title("Pie Chart ")
.Layout(Ext.Net.LayoutType.Fit)
.Frame(false)
.Height(300)
.Items(reportsPieChart);
var generatePDFButton = X.Button()
.ID("generatePDF")
.Text("Export PDF")
.DirectEvents(de =>
{
de.Click.IsUpload = true;
de.Click.Url = "/Report/GeneratePDF";
});
var testcaseReportsFormPanel = X.Panel()
.ID("reportsPanel")
.Title("Pie chart")
.Expand()
.Padding(20)
.Items(
generatePDFButton,
pieChartPanel
);
}
@section wizard_step
{
@(testcaseReportsFormPanel)
}
I am using itextsharp to generate PDF file. I am able to add image files to PDF document.
But before adding i need to save this pdf as an image and send reference of pie chart image file path to pdf document.
How can i save that above chart to image.
Please do the needful.
Regards,
Chinni