/// <summary>
        /// Gets the SVG histogram.
        /// </summary>
        /// <param name="model">The histogram model</param>
        /// <param name="is3D">if set to <c>true</c> it will be 3D</param>
        /// <param name="depth">The depth.</param>
        /// <returns></returns>
        public static String GetSVGHistogram(this histogramModel model, Boolean is3D = false, short depth = 10)
        {
            if (!is3D)
            {
                HistogramChart output = new HistogramChart(500, 360, model.targetBins);
                XmlDocument    xml    = output.GenerateChart(model.GetDataTableForFrequencies(), histogramModel.DEFAULT_COLUMN_NAME, histogramModel.DEFAULT_COLUMN_VALUE);

                return(xml.OuterXml);
            }
            else
            {
                Histogram3DChart output = new Histogram3DChart(500, 360, model.targetBins, depth);
                XmlDocument      xml    = output.GenerateChart(model.GetDataTableForFrequencies(), histogramModel.DEFAULT_COLUMN_NAME, histogramModel.DEFAULT_COLUMN_VALUE);

                return(xml.OuterXml);
            }
        }
Example #2
0
        private void Button1_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = openFileDialog1.ShowDialog();

            if (dialogResult.Equals(DialogResult.OK))
            {
                StreamReader fileIN;
                //  fileName = openFileDialog1.FileName;
                fileIN = new StreamReader(fileName);

                string   tableTitle = fileIN.ReadLine();
                string[] values;

                while (fileIN.Peek() != -1)
                {
                    values = fileIN.ReadLine().Split(',');
                    vehicleType.Add(values[0]);
                    vehicleYear2018Sales.Add(Int32.Parse(values[1]));
                    vehicleYear2019Sales.Add(Int32.Parse(values[2]));
                }
                fileIN.Close();
            }
            // Plotting the Data in a graph

            //salesBarGraph.Titles.Add(tableName);

            //salesBarGraph.Series.Add("2019");
            //salesBarGraph.Series[0].Points.DataBindY(vehicleYear2018Sales);
            //salesBarGraph.Series[0].LegendText = "2018";
            //salesBarGraph.Series[1].Points.DataBindY(vehicleYear2019Sales);
            //for (int i = 0; i < vehicleType.Count; i++)
            //    salesBarGraph.Series[0].Points[i].AxisLabel = vehicleType[i];
            //salesBarGraph.SaveImage("VehicleSales.emf", ChartImageFormat.Emf);
            //mktShareChart.Titles.Add("Market Share of Vehicles 2019");
            //mktShareChart.Series[0].Points.DataBindY(vehicleYear2019Sales);
            //mktShareChart.Series[0].LegendText = "2019";
            //for (int i=0; i<vehicleType.Count; i++)
            //mktShareChart.Series[0].Points[i].AxisLabel = vehicleType[i];
            //mktShareChart.SaveImage("Market Share of 2019.emf", ChartImageFormat.Emf);



            //Convert Charts To SVG

            DataTable table1 = new DataTable("Vehicle Sales 2018 & 2019"), table2 = new DataTable("2019 Market Share");

            //table1 = ConvertToDataTable(vehicleYear2018Sales);
            //table2 = ConvertToDataTable(vehicleYear2019Sales);
            table1.Columns.Add("Type", typeof(string));
            table1.Columns.Add("Quantity", typeof(double));
            table2.Columns.Add("Type", typeof(string));
            table2.Columns.Add("Quantity", typeof(double));

            for (int i = 0; i < vehicleYear2018Sales.Count; i++)
            {
                table1.Rows.Add("2018 " + vehicleType[i], vehicleYear2018Sales[i].ToString());
                table1.Rows.Add("2019 " + vehicleType[i], vehicleYear2019Sales[i].ToString());
                table2.Rows.Add(vehicleType[i], vehicleYear2019Sales[i].ToString());
            }

            SVGObject      svg = new SVGObject();
            HistogramChart his = new HistogramChart(300, 300, table1.Rows.Count);

            //his.
            // Credits to Gerard Viader
            XmlDocument xml = his.GenerateChart(table1, table1.Columns["Type"].ToString(), table1.Columns["Quantity"].ToString());

            xml.Save("2018 & 2019 Vehicle Sales.svg");

            PieChart pie = new PieChart(500, 500, table2.Rows.Count);

            xml = pie.GenerateChart(table2, table2.Columns["Type"].ToString(), table2.Columns["Quantity"].ToString());
            xml.Save("2019 Market Share.svg");

            //xml = his.GenerateChart(table1, table1.Columns["Type"].ToString(), table1.Columns["2019"].ToString());
            //xml.Save("2019 Market Share.svg");
            Application.Exit();
        }