Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. VS2010 chart Control [modified]

VS2010 chart Control [modified]

Scheduled Pinned Locked Moved C#
question
12 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Rutvik Dave

    As you already know, Bar Chart is 2 Axis chart, so you cannot hide any of the axis, otherwise it will not plot the chart. but you can make the Color of the Y Axis same as Background color of the Chart Area. So that It's there but not visible (kind of).

    Chart1.ChartAreas["ChartArea1"].AxisY.LabelStyle.ForeColor = "Your background color";
    Chart1.ChartAreas["ChartArea1"].AxisY.LineColor = "Your background color";
    Chart1.ChartAreas["ChartArea1"].AxisY.TitleForeColor = "Your background color";
    // + add any other color property that you don't want...

    Hopefully this should work... :) If you have gradient background, this is not going to work. Please Let us know, if you find out any other way to hide the Y-Axis

    K Offline
    K Offline
    kibromg
    wrote on last edited by
    #3

    Thanks for your email.Its much appreciated.That is great point,what i wouldnt want to show is the scale points as they are Revenue points which users are not allowed to see. The backcolor is white at the moment setting the forcolor to white wont show scale y axis. Chart1.ChartAreas["ChartArea1"].AxisY.LabelStyle.ForeColor="#FFFFFF" Did i get it right?

    R 1 Reply Last reply
    0
    • K kibromg

      Thanks for your email.Its much appreciated.That is great point,what i wouldnt want to show is the scale points as they are Revenue points which users are not allowed to see. The backcolor is white at the moment setting the forcolor to white wont show scale y axis. Chart1.ChartAreas["ChartArea1"].AxisY.LabelStyle.ForeColor="#FFFFFF" Did i get it right?

      R Offline
      R Offline
      Rutvik Dave
      wrote on last edited by
      #4

      kibromg wrote:

      Chart1.ChartAreas["ChartArea1"].AxisY.LabelStyle.ForeColor="#FFFFFF"

      It should be

      Chart1.ChartAreas["ChartArea1"].AxisY.LabelStyle.ForeColor = System.Drawing.Color.White;

      K 1 Reply Last reply
      0
      • R Rutvik Dave

        kibromg wrote:

        Chart1.ChartAreas["ChartArea1"].AxisY.LabelStyle.ForeColor="#FFFFFF"

        It should be

        Chart1.ChartAreas["ChartArea1"].AxisY.LabelStyle.ForeColor = System.Drawing.Color.White;

        K Offline
        K Offline
        kibromg
        wrote on last edited by
        #5

        Thanks so much. Sorry if you dont mind , I have another query.On my X axis for each scale points i have two bar graph. One is the target for the day and the other one is a progreess bar which indicates as we approach to that target. Lets say (x axis is Hours of the day) for instance at 8:00am i have a target of $1000 and this is shown with one Bargraph. and i have another one which is an online realtime data that counts as persentage to this value.So at exactly 8:00am it will be zero percent and after few minutes it will climb up this point until the hour finishes. and at 9:00 there will be another datapoints on x axis may be £2000 and another progreess bar that shows the progress etcc.. $1000 is 100% target for 8:00am and another bargraph toshow what is achieved say $500 so it will be at 50% £2000 is 100% target for 9:00am and another bargraph to toshow what is achieved say $4000 so it will be at 200% How can i represent one bargraph $1000 and another one saying 50% for one datapoint in X axis? Is it clear? -- Modified Wednesday, October 6, 2010 12:37 PM

        R 1 Reply Last reply
        0
        • K kibromg

          Thanks so much. Sorry if you dont mind , I have another query.On my X axis for each scale points i have two bar graph. One is the target for the day and the other one is a progreess bar which indicates as we approach to that target. Lets say (x axis is Hours of the day) for instance at 8:00am i have a target of $1000 and this is shown with one Bargraph. and i have another one which is an online realtime data that counts as persentage to this value.So at exactly 8:00am it will be zero percent and after few minutes it will climb up this point until the hour finishes. and at 9:00 there will be another datapoints on x axis may be £2000 and another progreess bar that shows the progress etcc.. $1000 is 100% target for 8:00am and another bargraph toshow what is achieved say $500 so it will be at 50% £2000 is 100% target for 9:00am and another bargraph to toshow what is achieved say $4000 so it will be at 200% How can i represent one bargraph $1000 and another one saying 50% for one datapoint in X axis? Is it clear? -- Modified Wednesday, October 6, 2010 12:37 PM

          R Offline
          R Offline
          Rutvik Dave
          wrote on last edited by
          #6

          Yes, You can do that, You will need to add one more series in your chart. so that there are total 2 series, one for target and another for progress. i.e.

          Chart1.Series.Add("Target");
          Chart1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar;
          Chart1.Series[0].IsValueShownAsLabel = true;
          Chart1.Series[0].LabelFormat = "#"; -- here you want just target money right ?

          Chart1.Series.Add("Progress");
          Chart1.Series[1].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar;
          Chart1.Series[1].IsValueShownAsLabel = true;
          Chart1.Series[1].LabelFormat = "#%"; -- this will show % progress

          now get the data set with all the 3 values as columns, time,target,progress. one column for x axes and 2 columns for y axes, and then

          Chart1.Series["Target"].Points.DataBindXY(ds["time"],ds["target"]);
          Chart1.Series["Progress"].Points.DataBindXY(ds["time"],ds["progress"]);

          now the ds["time"] will group the bars to gather if they have same time. and one will show value and another will show percentage. also the ds["percentage"] should have values without x 100, i.e. 0.40 for 40% and not 40... Also, I would suggest you, that you download[^] the mschart control samples. you will have sample for almost every single scenario.

          K 1 Reply Last reply
          0
          • R Rutvik Dave

            Yes, You can do that, You will need to add one more series in your chart. so that there are total 2 series, one for target and another for progress. i.e.

            Chart1.Series.Add("Target");
            Chart1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar;
            Chart1.Series[0].IsValueShownAsLabel = true;
            Chart1.Series[0].LabelFormat = "#"; -- here you want just target money right ?

            Chart1.Series.Add("Progress");
            Chart1.Series[1].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar;
            Chart1.Series[1].IsValueShownAsLabel = true;
            Chart1.Series[1].LabelFormat = "#%"; -- this will show % progress

            now get the data set with all the 3 values as columns, time,target,progress. one column for x axes and 2 columns for y axes, and then

            Chart1.Series["Target"].Points.DataBindXY(ds["time"],ds["target"]);
            Chart1.Series["Progress"].Points.DataBindXY(ds["time"],ds["progress"]);

            now the ds["time"] will group the bars to gather if they have same time. and one will show value and another will show percentage. also the ds["percentage"] should have values without x 100, i.e. 0.40 for 40% and not 40... Also, I would suggest you, that you download[^] the mschart control samples. you will have sample for almost every single scenario.

            K Offline
            K Offline
            kibromg
            wrote on last edited by
            #7

            Thanks so much its much appreciated.That is really great. I have a few questions if you dont mind.Lets say for 8:00am target is $1000 and achieved is $500 which is (50%) and 9:00am target is %2000 and Achieved is $4000 which is 200% On the first one the progress barchart whould be half target barchart. on the second one the progrees barchart should exceed the length of the target barchart twice. But this is not the case as the value 0.5 (50%) is to small in values on the scale points on Y axis though it means £500 which is half the value of the target. If i choose percentage it is a bit tricky to represnt them on graph? Where i am getting it wrong? Can you also please let me know how could i choose the backcolor of my barchart? Many thanks.Your help is great and much appreciated.

            R 1 Reply Last reply
            0
            • K kibromg

              Thanks so much its much appreciated.That is really great. I have a few questions if you dont mind.Lets say for 8:00am target is $1000 and achieved is $500 which is (50%) and 9:00am target is %2000 and Achieved is $4000 which is 200% On the first one the progress barchart whould be half target barchart. on the second one the progrees barchart should exceed the length of the target barchart twice. But this is not the case as the value 0.5 (50%) is to small in values on the scale points on Y axis though it means £500 which is half the value of the target. If i choose percentage it is a bit tricky to represnt them on graph? Where i am getting it wrong? Can you also please let me know how could i choose the backcolor of my barchart? Many thanks.Your help is great and much appreciated.

              R Offline
              R Offline
              Rutvik Dave
              wrote on last edited by
              #8

              OK, This is because the Axes Y, should bind same kind of values, due to same scale type. so those 0.5,0.1.. will be too small compared to 1000 (which is $ value). so you need to change few things... i.e.

              Chart1.Series.Add("Target");
              Chart1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar;
              Chart1.Series[0].IsValueShownAsLabel = true;
              Chart1.Series[0].LabelFormat = "#"; // here you want just target money right ?

              Chart1.Series.Add("Progress");
              Chart1.Series[1].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar;
              Chart1.Series[1].IsValueShownAsLabel = false; // i have changed this
              Chart1.Series[1].LabelFormat = "#"; // 'i have changed this also

              now in ds you will need 4 columns, or change the 3rd column from percentage to value. or just 4 columns

              1.time
              2.target // (this should be value like $1000)
              3.progress //(this should be value like $500)
              4.percentage // (this should be 50%)

              now you need to manually add the points, instead of binding it. so,

              Chart1.Series[0].Points.Clear();
              Chart1.Series[1].Points.Clear();

              foreach (DataRow dr in ds.Tables[0].Rows)
              {
              Chart1.Series[0].Points.AddXY(dr["time"],dr["target"]) // for first bar

              Chart1.Series[1].Points.AddXY(dr["time"],dr["progress"]) // for second bar value
              Chart1.Series[1].Points[Chart1.Series[1].Points.Count - 1].Label = dr["percentage"].ToString() + "%" //we have disabled the auto label, so here we define the label value, so it will have 500 as value in scale, but it will show 50 % as a label.

              }

              and to change the background color

              Chart1.ChartAreas[0].BackColor = System.Drawing.Color.Silver;

              And for my next answer, I need MONEY... :-D Just go through the sample code, I mentioned in the previous post. it has all the code. first you just run the sample project and browse the app, and if you find something interesting, look for the code. again you can download it here[^]

              K 1 Reply Last reply
              0
              • R Rutvik Dave

                OK, This is because the Axes Y, should bind same kind of values, due to same scale type. so those 0.5,0.1.. will be too small compared to 1000 (which is $ value). so you need to change few things... i.e.

                Chart1.Series.Add("Target");
                Chart1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar;
                Chart1.Series[0].IsValueShownAsLabel = true;
                Chart1.Series[0].LabelFormat = "#"; // here you want just target money right ?

                Chart1.Series.Add("Progress");
                Chart1.Series[1].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar;
                Chart1.Series[1].IsValueShownAsLabel = false; // i have changed this
                Chart1.Series[1].LabelFormat = "#"; // 'i have changed this also

                now in ds you will need 4 columns, or change the 3rd column from percentage to value. or just 4 columns

                1.time
                2.target // (this should be value like $1000)
                3.progress //(this should be value like $500)
                4.percentage // (this should be 50%)

                now you need to manually add the points, instead of binding it. so,

                Chart1.Series[0].Points.Clear();
                Chart1.Series[1].Points.Clear();

                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                Chart1.Series[0].Points.AddXY(dr["time"],dr["target"]) // for first bar

                Chart1.Series[1].Points.AddXY(dr["time"],dr["progress"]) // for second bar value
                Chart1.Series[1].Points[Chart1.Series[1].Points.Count - 1].Label = dr["percentage"].ToString() + "%" //we have disabled the auto label, so here we define the label value, so it will have 500 as value in scale, but it will show 50 % as a label.

                }

                and to change the background color

                Chart1.ChartAreas[0].BackColor = System.Drawing.Color.Silver;

                And for my next answer, I need MONEY... :-D Just go through the sample code, I mentioned in the previous post. it has all the code. first you just run the sample project and browse the app, and if you find something interesting, look for the code. again you can download it here[^]

                K Offline
                K Offline
                kibromg
                wrote on last edited by
                #9

                Thanks a million you are my hero Dave.Anything will be given for you man. Thanks. :) One last question : dr["time"] is coming as Y axis and the others like dr["progress"] are on X axis. How do i reverse it ?so the Dr{time} is X axis. Here is the Code:-- Dim dt As New DataTable With dt .Columns.Add(New DataColumn("Hour", System.Type.GetType("System.String"))) .Columns.Add(New DataColumn("Acheived", System.Type.GetType("System.String"))) .Columns.Add(New DataColumn("Hourly_target", System.Type.GetType("System.String"))) .Columns.Add(New DataColumn("Hourly_targetPer", System.Type.GetType("System.String"))) .PrimaryKey = New DataColumn() {dt.Columns("Hour")} End With Chart1.Series.Add("Hourly_target") Chart1.Series(0).ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar Chart1.Series(0).IsValueShownAsLabel = True Chart1.Series(0).LabelFormat = "#" ' here you want just target money right ? Chart1.Series.Add("Acheived") Chart1.Series(1).ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar Chart1.Series(1).IsValueShownAsLabel = False ' i have changed this Chart1.Series(0).LabelFormat = "#" Chart1.Series(0).XValueMember = "Hour" Chart1.Series(1).YValueMembers = "Hourly_target" Chart1.Series(0).Points.Clear() Chart1.Series(1).Points.Clear() For Each myDataRow As DataRow In dt.Rows Chart1.Series(0).Points.AddXY(myDataRow("Hour"), myDataRow("Hourly_target")) Chart1.Series(1).Points.AddXY(myDataRow("Hour"), myDataRow("Acheived")) Chart1.Series(1).Points(Chart1.Series(1).Points.Count - 1).Label = myDataRow("hourly_targetPer").ToString + "%" Next However i get x axis -- Hourly_target and Y axis is Hour. Is there anything i am missing ,It should be the reverse . sorry i meant to ask changing the color of the barchart not the backcolor. Thanks Dave -- Modified Thursday, October 7, 2010 1:36 PM

                R 1 Reply Last reply
                0
                • K kibromg

                  Thanks a million you are my hero Dave.Anything will be given for you man. Thanks. :) One last question : dr["time"] is coming as Y axis and the others like dr["progress"] are on X axis. How do i reverse it ?so the Dr{time} is X axis. Here is the Code:-- Dim dt As New DataTable With dt .Columns.Add(New DataColumn("Hour", System.Type.GetType("System.String"))) .Columns.Add(New DataColumn("Acheived", System.Type.GetType("System.String"))) .Columns.Add(New DataColumn("Hourly_target", System.Type.GetType("System.String"))) .Columns.Add(New DataColumn("Hourly_targetPer", System.Type.GetType("System.String"))) .PrimaryKey = New DataColumn() {dt.Columns("Hour")} End With Chart1.Series.Add("Hourly_target") Chart1.Series(0).ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar Chart1.Series(0).IsValueShownAsLabel = True Chart1.Series(0).LabelFormat = "#" ' here you want just target money right ? Chart1.Series.Add("Acheived") Chart1.Series(1).ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar Chart1.Series(1).IsValueShownAsLabel = False ' i have changed this Chart1.Series(0).LabelFormat = "#" Chart1.Series(0).XValueMember = "Hour" Chart1.Series(1).YValueMembers = "Hourly_target" Chart1.Series(0).Points.Clear() Chart1.Series(1).Points.Clear() For Each myDataRow As DataRow In dt.Rows Chart1.Series(0).Points.AddXY(myDataRow("Hour"), myDataRow("Hourly_target")) Chart1.Series(1).Points.AddXY(myDataRow("Hour"), myDataRow("Acheived")) Chart1.Series(1).Points(Chart1.Series(1).Points.Count - 1).Label = myDataRow("hourly_targetPer").ToString + "%" Next However i get x axis -- Hourly_target and Y axis is Hour. Is there anything i am missing ,It should be the reverse . sorry i meant to ask changing the color of the barchart not the backcolor. Thanks Dave -- Modified Thursday, October 7, 2010 1:36 PM

                  R Offline
                  R Offline
                  Rutvik Dave
                  wrote on last edited by
                  #10

                  It is correct if you select Bar Chart, I think, you want Column Chart. Change

                  ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar

                  //to

                  ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Column

                  kibromg wrote:

                  sorry i meant to ask changing the color of the barchart not the backcolor.

                  I though that,

                  kibromg wrote:

                                Chart1.Series(0).Points.AddXY(myDataRow("Hour"), myDataRow("Hourly\_target"))
                                Chart1.Series(1).Points.AddXY(myDataRow("Hour"), myDataRow("Acheived"))
                                Chart1.Series(1).Points(Chart1.Series(1).Points.Count - 1).Label = myDataRow("hourly\_targetPer").ToString + "%"
                  

                  here add

                  Chart1.Series(1).Points(Chart1.Series(1).Points.Count - 1).Color = System.Drawing.Color.Red

                  I think, you want to change the color based on progress, yeah you can do that...just add some IFs...

                  K 1 Reply Last reply
                  0
                  • R Rutvik Dave

                    It is correct if you select Bar Chart, I think, you want Column Chart. Change

                    ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar

                    //to

                    ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Column

                    kibromg wrote:

                    sorry i meant to ask changing the color of the barchart not the backcolor.

                    I though that,

                    kibromg wrote:

                                  Chart1.Series(0).Points.AddXY(myDataRow("Hour"), myDataRow("Hourly\_target"))
                                  Chart1.Series(1).Points.AddXY(myDataRow("Hour"), myDataRow("Acheived"))
                                  Chart1.Series(1).Points(Chart1.Series(1).Points.Count - 1).Label = myDataRow("hourly\_targetPer").ToString + "%"
                    

                    here add

                    Chart1.Series(1).Points(Chart1.Series(1).Points.Count - 1).Color = System.Drawing.Color.Red

                    I think, you want to change the color based on progress, yeah you can do that...just add some IFs...

                    K Offline
                    K Offline
                    kibromg
                    wrote on last edited by
                    #11

                    Hello Dave.Hope you doing great my hero. I have one final question. Your help is really great. I would like to put a a dolar sign before the values on each of the colomn bar. That is the amount of the target(in dolar) on top of each column bar. Chart1.ChartAreas(0).AxisY.LabelStyle.Format = "C" wil give the Y axis points to have Dolar sign. How do i do it for each of the coloumn in the Graph both taget and achieved one? Thanks once again dave. Cheers

                    R 1 Reply Last reply
                    0
                    • K kibromg

                      Hello Dave.Hope you doing great my hero. I have one final question. Your help is really great. I would like to put a a dolar sign before the values on each of the colomn bar. That is the amount of the target(in dolar) on top of each column bar. Chart1.ChartAreas(0).AxisY.LabelStyle.Format = "C" wil give the Y axis points to have Dolar sign. How do i do it for each of the coloumn in the Graph both taget and achieved one? Thanks once again dave. Cheers

                      R Offline
                      R Offline
                      Rutvik Dave
                      wrote on last edited by
                      #12

                      You can try this,

                      Chart1.Series[0].LabelFormat = "C";
                      // or
                      Chart1.Series[1].LabelFormat = "C";

                      more information about formatting a label, here[^] and here[^].

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups