Sign UpSign Up   Sign InSign In Welcome Guest,
Live Chat Live Chat

The secondary axis in a Line Column chart doesn't display

Last post 07-01-2009, 7:27 AM by nausherwan.aslam. 5 replies.
Sort Posts: Previous Next
  •  07-01-2009, 4:09 AM 186297

    The secondary axis in a Line Column chart doesn't display .NET

    Attachment: Present (inaccessible)

    I am trying to create a Line Column chart. One series is Column and is plotted on Y axis. The other is a Line series and is plotted on secondary Y Axis. I use the following code to do so.

     

    chart.NSeries.Add(worksheet.Name + "!B2:" + cellName, true);

    chart.NSeries.CategoryData = worksheet.Name + "!A2:A" + rowcount;

    chart.NSeries[1].Type = ChartType.Line;

    chart.NSeries[1].PlotOnSecondAxis = true;

    chart.SecondValueAxis.IsVisible = true;

     

    The secondary Axis doesn't display. However it is present in the template. I have attached the template which I am using.

     
  •  07-01-2009, 4:51 AM 186313 in reply to 186297

    Re: The secondary axis in a Line Column chart doesn't display

    Hi,

     

    Thank you for considering Aspose.

     

    Please set the chart.NSeries[1].Line.IsVisible = trueto show the line. Please see the following updated code for your reference,

     

    chart.NSeries.Add(worksheet.Name + "!B2:" + cellName, true);

     

    chart.NSeries.CategoryData = worksheet.Name + "!A2:A" + rowcount;

     

    chart.NSeries[1].Type = ChartType.Line;

     

    chart.NSeries[1].PlotOnSecondAxis = true;

     

    chart.SecondValueAxis.IsVisible = true;

     

    chart.NSeries[1].Line.IsVisible = true;

     

    chart.NSeries[1].Line.Color = System.Drawing.Color.DarkBlue;

     

    chart.NSeries[1].MarkerStyle = ChartMarkerType.Circle;

     

    chart.NSeries[1].MarkerBackgroundColor = System.Drawing.Color.DarkBlue;

     

    chart.NSeries[1].MarkerForegroundColor = System.Drawing.Color.DarkBlue;

     

    chart.NSeries[1].MarkerSize = 5;

     

     

    Thank You & Best Regards,


    Nausherwan Aslam
    Support Developer,
    Aspose Sialkot Team
    Contact Us
     
  •  07-01-2009, 4:58 AM 186317 in reply to 186313

    Re: The secondary axis in a Line Column chart doesn't display

    Hi,

    This is the code to modify the "Line" series stryle. But the issue which I am facing is that - The secondary Y Axis does not show up with this code. The output chart has just 2 Axis, the X and the Y.

     
  •  07-01-2009, 5:14 AM 186323 in reply to 186297

    Re: The secondary axis in a Line Column chart doesn't display

    Attachment: Present (inaccessible)
    Hi,

    Well, it works fine without any issue, I have written the sample code using your template file to create your desired chart, the output file is also attached. You can modify my code accordingly too.

    Sample code:

                     //Instantiating a Workbook object
                      Workbook workbook = new Workbook();
                      workbook.Open("f:\\test\\ChartsTemplate.xls");

                      //Defind custom colors.
                      Color color1, color2;
                      color1 = Color.FromArgb(153, 51, 102);
                      color2 = Color.FromArgb(0, 0, 128);
                      //Add to excel color palette.
                      workbook.ChangePalette(color1, 55);
                      workbook.ChangePalette(color2, 54);

                      //Adding a new worksheet to the Workbook object
                      int sheetIndex = workbook.Worksheets.Add(SheetType.Chart);
                      //Obtaining the reference of the newly added worksheet by passing its sheet index
                      Worksheet worksheet = workbook.Worksheets[sheetIndex];

                      //Adding a chart to the worksheet
                      int chartIndex = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5);
                      //Accessing the instance of the newly added chart
                      Chart chart = worksheet.Charts[chartIndex];
                      //Adding NSeries (chart data source)
                      chart.NSeries.Add("=LineColumnSheet!B2:C9", true);
                      chart.NSeries.CategoryData = "=LineColumnSheet!A2:A9";
                      chart.NSeries.SecondCatergoryData = "=LineColumnSheet!A2:A9";

                      //Set the first series color.
                      chart.NSeries[0].Area.ForegroundColor = color1;

                      //Setting the chart type of 2nd NSeries to display as line chart
                      chart.NSeries[1].Type = ChartType.Line;
                      chart.NSeries[1].PlotOnSecondAxis = true;
                      chart.NSeries[1].Line.Color = color2;
                      chart.NSeries[1].Line.Style = LineType.Solid;
                      chart.NSeries[1].Line.Weight = WeightType.SingleLine;
                      chart.NSeries[1].MarkerStyle = ChartMarkerType.Circle;
                      chart.NSeries[1].MarkerSize = 5;
                      chart.NSeries[1].MarkerForegroundColor = color2;
                      chart.NSeries[1].MarkerBackgroundColor = color2;
                      chart.SecondValueAxis.IsVisible = true;

                      chart.NSeries[0].Name = workbook.Worksheets["LineColumnSheet"].Cells["B1"].Value.ToString();
                      chart.NSeries[1].Name = workbook.Worksheets["LineColumnSheet"].Cells["C1"].Value.ToString();

                      chart.ChartArea.Border.IsVisible = false;
                      chart.ChartArea.Area.ForegroundColor = Color.Transparent;
                      chart.PlotArea.Border.IsVisible = false;
                      chart.PlotArea.Area.ForegroundColor = Color.Transparent;
                      chart.Legend.Position = LegendPositionType.Top;
                      chart.IsLegendShown = true;

                      //Saving the Excel file
                      workbook.Save("f:\\test\\output_ChartsTemplates.xls", FileFormatType.Default);

     

     

    Thank you.


    Amjad Sahi
    Support Developer,
    Aspose Sialkot Team
    Contact Us
     
  •  07-01-2009, 6:46 AM 186345 in reply to 186323

    Re: The secondary axis in a Line Column chart doesn't display

    I missed one line in the code -

    chart.NSeries.SecondCatergoryData = "=LineColumnSheet!A2:A9";

    But even this does not help. When I execute this line of code, nothing is set on the SecondCategoryData. It remains empty. And the output chart does not show the secondary axis.

     

     
  •  07-01-2009, 7:27 AM 186365 in reply to 186345

    Re: The secondary axis in a Line Column chart doesn't display

    Hi,

    Thank you for considering Aspose.

    If you want to show the second category data then you have to set chart.SecondCategoryAxis.IsVisible = true; in your code. Please try it and let us know if it works fine for you.

    Thank You & Best Regards,


    Nausherwan Aslam
    Support Developer,
    Aspose Sialkot Team
    Contact Us
     
View as RSS news feed in XML