Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
HI,
 
I am new in MS Chart but i want to a chart with database. I found many article on net but my requirement is different.
In My database I have table "UserTAT" and its Column Name is "INTAT" , "OUTTAT" , "PASSTAT"
and these column contain only integer value. like this.
 
Table Name: - UserTAT
 
Column Name: INTAT OUTTAT PASSTAT
Row Value : 2 4 10
4 6 20
 
Now i want to column name in x-aisx and column value in y-asix. Please Help me to solve this problem. Please check image link to see chart type i want. Help.
http://rashtriyasakshartamission.com/chartsample.png
 
Thanks
Posted 13-Jan-13 7:51am
Edited 13-Jan-13 10:58am
v3
Comments
NeerajBhagat09 at 13-Jan-13 16:18pm
   
Do you want the graph for a single row?
ram_kumar at 14-Jan-13 11:24am
   
yes sir
jkirkerx at 13-Jan-13 19:22pm
   
Are you doing this in code behind, pure code, or are you using the control object in design view?
 
Are you using 3.5 or 4.0?
ram_kumar at 14-Jan-13 11:23am
   
I am using 4.0
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I assume your using the design view to build your chart
 
First, you need to know that there is the chart and there are series.
 
You place the chart object on your webform first, and size it, and then paint it, using the properties F4. When you have designed your chart, then you can build series, which are the data points. So start with adding manual data points first to learn how to build a series.
 
When you chart looks good, now you can attach your data to the chart.
 
So now you go to the code behind page, and make a reference to the chart, in which you create a new series, and then add the series to the chart.
 
The link below shows how to write code for series, and attach it to the chart.
 

http://www.mschartcontrol.blogspot.com/[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If I do not misunderstand you, you need the effect of below code, since I create an excel worksheet which is like below format:
 
A B C
2 4 10
4 6 20
 
Then, I create chart as below code by this application: http://spreadsheet.codeplex.com/[^]I hope it works for you!
 
        private void button1_Click(object sender, EventArgs e)
        {
            Workbook workbook = new Workbook();
            //Initialize worksheet
            workbook.LoadFromFile(@"D:\Demos\Data\chart.xlsx");
            Worksheet sheet = workbook.Worksheets[0];
 
            //Add Chart and Set Chart Data Range
            Chart chart = sheet.Charts.Add(ExcelChartType.ColumnClustered);
            chart.DataRange = sheet.Range["A2:C3"];
            chart.SeriesDataFromRange = true;
 
            //Chart Position
            chart.LeftColumn = 1;
            chart.TopRow = 6;
            chart.RightColumn = 12;
            chart.BottomRow = 25;
 
            //Chart Border
            chart.ChartArea.Border.Weight = ChartLineWeightType.Medium;
            chart.ChartArea.Border.Color = Color.SandyBrown;
 
            //Chart Title
            chart.ChartTitle = "UserTAT";
            chart.ChartTitleArea.Font.FontName = "Calibri";
            chart.ChartTitleArea.Font.Size = 13;
            chart.ChartTitleArea.Font.IsBold = true;
 
            //Chart Axes

            chart.PrimaryCategoryAxis.Font.Color = Color.SaddleBrown;
 
            chart.PrimaryValueAxis.Title = "Amounts";
            chart.PrimaryValueAxis.HasMajorGridLines = false;
            chart.PrimaryValueAxis.MaxValue = 30;
            chart.PrimaryValueAxis.TitleArea.TextRotationAngle = 90;
 
            workbook.SaveToFile("Sample1.xlsx");
            ExcelDocViewer(workbook.FileName);
        }
 

        private void ExcelDocViewer(string fileName)
        {
            try
            {
                System.Diagnostics.Process.Start(fileName);
            }
            catch { }
        }
    }
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 269
1 OriginalGriff 180
2 DamithSL 180
3 Peter Leow 125
4 Kornfeld Eliyahu Peter 95
0 OriginalGriff 7,355
1 DamithSL 5,254
2 Sergey Alexandrovich Kryukov 4,942
3 Maciej Los 4,906
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100