2
A
回答
3
您可以添加2行CustomLabels的,例如:
private void FillChart()
{
// fill the data table with values
var dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("City", typeof(string));
dt.Columns.Add("State", typeof(string));
dt.Columns.Add("Population", typeof(int));
dt.Rows.Add(0, "City1", "State1", 100);
dt.Rows.Add(1, "City2", "State1", 30);
dt.Rows.Add(2, "City3", "State1", 40);
dt.Rows.Add(3, "City1", "State2", 80);
dt.Rows.Add(4, "City2", "State2", 70);
// bind the data table to chart
this.chart1.Series.Clear();
var series = this.chart1.Series.Add("Series 1");
series.XValueMember = "Id";
series.YValueMembers = "Population";
series.ChartType = SeriesChartType.Column;
this.chart1.DataSource = dt;
this.chart1.DataBind();
// custom labels
foreach (var g in dt.AsEnumerable().GroupBy(x => x.Field<string>("State")))
{
string state = g.Key;
var cities = g.Select(r => new { Id = r.Field<int>("Id"), City = r.Field<string>("City") });
// find min-max
int min = cities.Min(y => y.Id);
int max = cities.Max(y => y.Id);
// city labels
foreach (var city in cities)
{
var label = new CustomLabel(city.Id - 1, city.Id + 1, city.City, 0, LabelMarkStyle.None);
this.chart1.ChartAreas[0].AxisX.CustomLabels.Add(label);
}
// city states
var statelabel = new CustomLabel(min, max, state, 1, LabelMarkStyle.LineSideMark);
this.chart1.ChartAreas[0].AxisX.CustomLabels.Add(statelabel);
}
}
結果是很相似的:
相關問題
- 1. d3.js:在x軸上顯示小時,分鐘,秒,毫秒
- 2. 以秒,毫秒顯示datediff
- 3. wxMathPlot x軸以毫秒爲單位?
- 4. Highcharts - X軸應該只顯示天,一個月,隱藏毫秒
- 5. JFreechart甘特圖毫秒X軸?
- 6. 毫秒級的jQuery秒錶
- 7. Highcharts顯示日期軸(毫秒)
- 8. 無法在X軸上顯示毫秒數股票Amcharts
- 9. 顯示毫秒
- 10. ggplot2:如何在x軸上顯示完整的時間戳(毫秒)?
- 11. 如何在C#中使秒錶顯示秒和毫秒?
- 12. 如何製作顯示毫秒的天文臺秒錶?
- 13. 如何在毫秒級的Android中顯示日期和時間?
- 14. 如何在毫秒中減去microtime和顯示日期以毫秒?
- 15. X毫秒
- 16. 如何在labview中修改波形圖以毫秒而不是秒顯示時間軸?
- 17. X毫秒後替換並循環顯示圖像
- 18. Wireshark:以毫秒顯示時間?
- 19. 樞軸紀錄的毫秒
- 20. Javascript以毫秒爲單位顯示毫秒數:小時:無秒數分鐘
- 21. PHPExcel:顯示圖表X軸標籤
- 22. 顯示CFGregorianDate而不毫秒
- 23. 在matplotlib中顯示毫秒
- 24. 用於顯示毫秒
- 25. 在Excel中顯示毫秒
- 26. 如何以毫秒顯示ssms中的執行時間?
- 27. Android秒錶:兩位數毫秒
- 28. 如何將像素(手機的顯示寬度)轉換爲毫秒(毫秒)?
- 29. 以100毫秒的間隔在java中顯示圖像
- 30. 在圖中顯示整個X軸蜱