Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how can i put background color in line graph using below attached code....
C#
private void chart_bind()
{
  DataTable dt = new DataTable();
  try
  {
      dt = GetData();

      str.Append(@"<script type=text/javascript> google.load( *visualization*, *1*, {packages:[*corechart*]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
      var data = new google.visualization.DataTable();
      data.addColumn('string', 'time');
      data.addColumn('number', 'price');
      data.addRows(" + dt.Rows.Count + ");");

      Int32 i;

      for (i = 0; i <= dt.Rows.Count - 1; i++)
      {
          str.Append("data.setValue( " + i + "," + 0 + "," + "'" + dt.Rows[i]["time"].ToString() + "');");
          str.Append("data.setValue(" + i + "," + 1 + "," + dt.Rows[i]["price"].ToString() + ") ;");
      }

      str.Append("   var chart = new google.visualization.LineChart(document.getElementById('chart_div'));");

      str.Append(" chart.draw(data, {width: 660, height: 300,title: '',");
      str.Append("hAxis: {title: 'Time', titleTextStyle: {color: 'green'}}");
      str.Append("}); }");
      str.Append("</script>");
      lt.Text = str.ToString().TrimEnd(',').Replace('*', '"');
  }
  catch
  { }
}
Posted
v2

1 solution

You need to add the color inside options. Something like below would work I believe.
JavaScript
str.Append(" chart.draw(data, {backgroundColor: 'black', width: 660, height: 300,title: '',");

Refer - Changing background colour of a Google Charts (Google Visualization) Graph[^].
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900