Ejemplo n.º 1
0
        static void CreateChart(IDrawing drawing, ISheet sheet, IClientAnchor anchor, string serie1, string serie2, bool enableMajorGridline = false)
        {
            XSSFChart chart = (XSSFChart)drawing.CreateChart(anchor);

            chart.SetTitle("Test 1");
            IChartLegend legend = chart.GetOrCreateLegend();

            legend.Position = LegendPosition.TopRight;

            ILineChartData <double, double> data = chart.ChartDataFactory.CreateLineChartData <double, double>();

            // Use a category axis for the bottom axis.
            IChartAxis bottomAxis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom);
            IValueAxis leftAxis   = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left);

            leftAxis.Crosses = AxisCrosses.AutoZero;

            IChartDataSource <double> xs  = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
            IChartDataSource <double> ys1 = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(1, 1, 0, NUM_OF_COLUMNS - 1));
            IChartDataSource <double> ys2 = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(2, 2, 0, NUM_OF_COLUMNS - 1));

            var s1 = data.AddSeries(xs, ys1);

            s1.SetTitle(serie1);
            var s2 = data.AddSeries(xs, ys2);

            s2.SetTitle(serie2);

            chart.Plot(data, bottomAxis, leftAxis);
            //add major gridline, available since NPOI 2.5.5
            var plotArea = chart.GetCTChart().plotArea;

            plotArea.catAx[0].AddNewMajorGridlines();
            plotArea.valAx[0].AddNewMajorGridlines();
        }
Ejemplo n.º 2
0
        public void TestExistingChartNoTitle()
        {
            IWorkbook wb    = XSSFTestDataSamples.OpenSampleWorkbook("chartTitle_noTitle.xlsx");
            XSSFChart chart = GetChartFromWorkbook(wb, "Sheet1");

            Assert.IsNotNull(chart);
            Assert.IsNull(chart.Title);
            String myTitle = "My chart title";

            chart.SetTitle(myTitle);
            XSSFRichTextString queryTitle = chart.Title;

            Assert.IsNotNull(queryTitle);
            Assert.AreEqual(myTitle, queryTitle.ToString());
        }
Ejemplo n.º 3
0
        public void TestNewChart()
        {
            IWorkbook wb    = CreateWorkbookWithChart();
            XSSFChart chart = GetChartFromWorkbook(wb, "linechart");

            Assert.IsNotNull(chart);
            Assert.IsNull(chart.Title);
            String myTitle = "My chart title";

            chart.SetTitle(myTitle);
            XSSFRichTextString queryTitle = chart.Title;

            Assert.IsNotNull(queryTitle);
            Assert.AreEqual(myTitle, queryTitle.ToString());
        }